A plot in the browser

Edit and run a NumPy and Matplotlib notebook with Pyodide.

Choose Run in browser above to open this notebook in JupyterLite. Use Run > Run All Cells to draw the plot.

Draw two curves

NumPy makes the numbers, and Matplotlib draws the curves. Change np.sin(x) to np.sin(2 * x), then run the cell again.

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-np.pi, np.pi, 160)
fig, ax = plt.subplots(figsize=(7, 3.5))
ax.plot(x, np.sin(x), label="sin(x)")
ax.plot(x, np.cos(x), label="cos(x)")
ax.set(xlabel="x", ylabel="Value", title="Sine and cosine")
ax.legend()
fig.tight_layout()
plt.show()

Packages

smalldocs finds numpy and matplotlib in the imports. The download contains a copied notebook with those dependencies in a PEP 723 comment block.