The matplotlib workbench

Pyodide, preloaded np and plt, plt.show(), files, savefig, and privacy.

The Matplotlib app is a Python editor that runs in WebAssembly (Pyodide). When the status line says matplotlib is ready, these names already exist:

  • np — NumPy
  • plt — matplotlib.pyplot

You do not write the imports unless you want to.

Goal

Know how Run, plt.show(), files, Reset, and savefig work before a blank Plot panel surprises you.

Run code

Paste into the editor and press Ctrl+Enter (Windows/Linux) or Cmd+Enter (macOS). The console is stdout. The Plot panel is for figures.

print("numpy", np.__version__)
print("matplotlib", plt.matplotlib.__version__)
plt.plot([0, 1, 2], [0, 1, 4], marker="o")
plt.title("n squared")
plt.show()

You should see a version pair in the console and a line in the Plot panel.

plt.show() is required

This is not Jupyter. A bare plt.plot(...) does not display. End every script with plt.show().

Files live in /uploads

Click Add files and choose a CSV or .txt file. After that:

import os

print(os.listdir("/uploads"))

Readable paths: rainfall.csv or /uploads/rainfall.csv.

Writes become download chips

import os

plt.plot([1, 2, 3], [1, 4, 9])
plt.title("demo")
plt.savefig("demo.png", dpi=100, bbox_inches="tight")
plt.show()
print("wrote demo.png")
print(os.listdir("/uploads"))

After Run, click on the file chip. Nothing is uploaded to Swiftener’s servers.

Reset, autosave, snippets

  • Code autosaves in this browser.
  • Reset restores the starter snippet — it does not delete /uploads.
  • Clear on the Plot panel removes figures without resetting the editor.

Privacy

Python runs in this tab. Uploads live in IndexedDB on this device. Lesson pages are public HTML; they never see your figures.

Pitfall

Do not paste %matplotlib inline or seaborn examples here. Print arrays and call plt.show(). Seaborn belongs in the Seaborn workbench.