Skip to main content
Use Matplotlib, Seaborn, or another installed Python plotting library for static charts. Displayed figures are returned as rich notebook outputs, and saved files are available through artifacts or normal filesystem reads.
result = sandbox.run_code("""
import matplotlib.pyplot as plt

plt.figure(figsize=(4, 3))
plt.bar(["A", "B", "C"], [3, 7, 5])
plt.title("Example chart")
plt.tight_layout()
plt.savefig("/workspace/chart.png")
plt.show()
""")

png_outputs = [
    item for item in result.results
    if item.png or (item.data and "image/png" in item.data)
]
print(len(png_outputs))
Download a saved chart from the sandbox:
chart_bytes = sandbox.files.read("/workspace/chart.png", format="bytes")