Matplotlib Introduction
Matplotlib is Python's most popular plotting library, and with PyScript, you can run it directly in your browser! Create interactive visualizations, charts, and graphs without any server-side processingโall powered by WebAssembly and Pyodide.
Key Features:
- Full Matplotlib Support: Access the complete matplotlib API in the browser
- NumPy Integration: Use NumPy arrays for data manipulation
- Interactive Charts: Create line plots, bar charts, scatter plots, and more
- Customization: Full control over colors, styles, labels, and layout
- Zero Backend: All rendering happens client-side
The Examples:
- Example 1: Line Plot - Shows a sine wave with customized styling
- Example 2: Bar Chart - Demonstrates categorical data visualization
- Example 3: Scatter Plot - Visualizes data correlation with color mapping
Getting Started:
To use Matplotlib in PyScript, you need to specify it in your config:
<py-config>
packages = ["matplotlib", "numpy"]
</py-config>
<script type="py">
from pyscript import display
import matplotlib.pyplot as plt
# Create your plots
fig, ax = plt.subplots()
# ... customize your plot
display(fig, target="output-div")
</script> Note: Matplotlib plots are rendered as static images in PyScript. For interactive plots, consider using Bokeh (see Bokeh examples).
Use Cases:
- Data visualization dashboards
- Scientific and educational demonstrations
- Statistical analysis presentations
- Report generation with charts