Toyplot is a powerful Python library designed to create simple, interactive, and publication-quality visualizations. It enables users to generate a variety of plots such as line charts, bar charts, scatter plots, and more, with an easy-to-use API that allows for quick implementation and customization. Unlike other traditional plotting libraries like Matplotlib, Toyplot emphasizes interactivity, smooth animations, web embedding capabilities, and clean, concise code. This makes it a compelling choice for data scientists, researchers, and developers who need an intuitive plotting tool with advanced features that work well with modern web technologies.
Toyplot stands out because of its ability to export plots as interactive HTML, generate SVG-based high-quality visuals, and provide built-in features like tooltips and animations. This makes it ideal for web-based projects, real-time data monitoring, business dashboards, and scientific visualizations, which require dynamic, easy-to-understand visual feedback.
To install Toyplot, run:
pip install toyplot
After installation, import it in your Python script or Jupyter Notebook:
import toyplot
import numpy as np
1. Simple and concise API
2. Interactive elements
3. Multiple chart types Toyplot supports a wide variety of visualizations, including:
4. Web-friendly embedding
5. Built-in data exporting
1. Lightweight and Minimalist
Toyplot requires minimal setup to generate clean, high-quality plots.
import toyplot
# Create a simple line plot
canvas = toyplot.Canvas(width=500, height=300)
axes = canvas.cartesian()
axes.plot([1, 2, 3, 4, 5], [10, 15, 5, 20, 10], color="blue")
canvas
A clean, simple line plot.
2. Interactive & Web-Friendly (Tooltips Example)
import toyplot
import numpy as np
# Define five points
x = np.array([1, 2, 3, 4, 5])
y = np.array([5, 3, 8, 6, 4])
# Create a canvas
canvas = toyplot.Canvas(width=400, height=300)
# Create an axis
axes = canvas.cartesian()
# Create a scatter plot with tooltips
scatterplot = axes.scatterplot(
x, y, color="blue", size=10, title=[f"({xi}, {yi})" for xi, yi in zip(x, y)]
)
# Display the plot
canvas
Hovering over a point shows its tooltip. (in this case coordinates of the point)
3. Declarative API (Multiple Series in One Plot)
import toyplot
# Create a canvas
canvas = toyplot.Canvas(width=600, height=400)
axes = canvas.cartesian()
# Define multiple series
series_1 = axes.plot([1, 2, 3, 4, 5], [10, 15, 5, 20, 10], color="blue")
series_2 = axes.plot([1, 2, 3, 4, 5], [5, 10, 15, 10, 5], color="green")
canvas
Two line plots with automatic legend.
4. Multiple Coordinate Systems (Logarithmic Scale Example)
import toyplot
canvas = toyplot.Canvas(width=600, height=400)
axes = canvas.cartesian(xscale="log", yscale="log")
# Logarithmic plot
axes.plot([1, 10, 100, 1000], [1, 10, 100, 1000], color="purple")
canvas
Logarithmic plot on both axes, while the same plot requires more than 20 lines of code in matplotlib
5. High-Quality Vector Output (Exporting to PDF/SVG)
import toyplot.pdf
canvas = toyplot.Canvas(width=600, height=400)
axes = canvas.cartesian()
axes.plot([1, 2, 3, 4], [5, 10, 15, 20])
# Save as PDF
toyplot.pdf.render(canvas, "output.pdf")
A high-resolution PDF file is generated.
6. Supports Animation (Time-Series Example)
import numpy
import toyplot
canvas = toyplot.Canvas(width=600, height=400)
axes = canvas.cartesian()
# Animated sine wave
x = numpy.linspace(0, 2 * numpy.pi, 50)
y = numpy.sin(x)
axes.plot(x, y, color="blue")
canvas
A dynamic sine wave plot.
7. Animated Line Plot ( Saved as HTML and Opened in Browser)
import toyplot
import numpy as np
import webbrowser
# Create a canvas
canvas = toyplot.Canvas(width=600, height=400)
axes = canvas.cartesian()
# Data points
x = np.array([1, 2, 3, 4, 5])
frames = 10
# Generate animated y-values (simulating changes over time)
y1_frames = np.column_stack([np.array([3, 7, 2, 8, 6]) + np.random.rand(5) * 2 for _ in range(frames)])
y2_frames = np.column_stack([np.array([4, 6, 3, 9, 7]) + np.random.rand(5) * 2 for _ in range(frames)])
# Plot the animated lines
axes.plot(x, y1_frames, color="blue", style={"stroke-width": "2px"})
axes.plot(x, y2_frames, color="red", style={"stroke-width": "2px"})
# Save as HTML
html_file = "animated_plot.html"
toyplot.html.render(canvas, html_file)
# Automatically open in the default browser
webbrowser.open(html_file)
print(f"Animated plot saved as {html_file} and opened in the browser.")
Animated plot saved as animated_plot.html and opened in the browser.
HTML file gets saved and is opened in the browser
1. Interactive Data Dashboards
Great for real-time analytics in Jupyter Notebooks.
Can be embedded into Flask or Django applications.
2. Scientific Data Visualization
Ideal for climate data, AI training performance, and research visualization.
Enables dynamic hover effects for better data exploration.
3. Business Intelligence & Reports
Supports high-quality, web-exportable figures for reports.
Best suited for financial, sales, and operational dashboards.
4. IoT & Real-Time Monitoring
Useful for sensor data visualization (e.g., temperature tracking, parking slot monitoring).
Plots update dynamically with real-time values.
Best for: Scientists, data analysts, web developers, and educators looking for interactive, publication-ready plots.
Toyplot is a modern, interactive, and lightweight alternative to Matplotlib, making it a powerful choice for web-based, scientific, and business visualization needs. With features like built-in interactivity, HTML export, and seamless Jupyter integration, it outshines traditional tools in areas that demand responsiveness and ease of use.
Official Toyplot Documentation: https://toyplot.readthedocs.io/en/stable/
GitHub Repository: https://github.com/sandialabs/toyplot