packages = ["bokeh", "pandas", "numpy", "networkx", "diagrams", "scikit-learn", "pillow", "matplotlib", "plotly"] [[fetch]] files = ["diagrams_base.py"] from = "../../python/diagrams/" [[fetch]] files = ["pyscript_manager.py", "data.py"] to_folder = "lib" from = "../../python/lib/" [[fetch]] files = ["bokeh_utils.py"] from = "../../python/bokeh/" [[fetch]] files = ["matplotlib_utils.py", "plotly_utils.py"] from = "../../python/matplotlib/" [[fetch]] files = ["agent.py", "trainer.py", "utils.py", "metrics_chart.py", "crossover.py", "__init__.py"] to_folder = "ml/neuro" from = "../../python/ml/neuro/" [[fetch]] files = ["trainer.py"] to_folder = "ml/grokking" from = "../../python/ml/grokking/"

Loading...

Example 1: Simple Line Plot

A basic line chart with matplotlib:


Example 2: Bar Chart

A colorful bar chart:


Example 3: Scatter Plot

Data correlation visualization:

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

๐Ÿ Python Console