plt.savefig writes a PNG (or SVG) under /uploads. After Run, click ↓ on the file chip. You can still plt.show() in the same script.
Goal
Save a PNG with dpi and tight bounding box, then confirm it appears in /uploads.
PNG
import os
x = np.linspace(0, 2 * np.pi, 80)
fig, ax = plt.subplots()
ax.plot(x, np.sin(x))
ax.set_title("sine")
fig.savefig("sine.png", dpi=120, bbox_inches="tight")
plt.show()
print("uploads:", os.listdir("/uploads"))bbox_inches="tight" trims leftover margin around the title.
SVG
import os
fig, ax = plt.subplots()
ax.bar(["A", "B", "C"], [12, 7, 2])
ax.set_title("units")
fig.savefig("units.svg")
plt.show()
print([n for n in os.listdir("/uploads") if n.endswith(".svg")])SVG stays sharp when you scale it. Spreadsheets and slides more often want PNG.
Order
Call savefig before or after show — both work here. If a chip is missing, print os.listdir("/uploads") and use a bare filename such as fig.png.
Tip
dpi=120 is enough for this panel. Use 200 if you will drop the PNG into a document.