Matplotlib online compiler
Write Matplotlib or seaborn code below and run it free, in a sandbox on our servers. plt.show() saves each chart as an image that appears under the output. No sign-in, no ads.
import matplotlib.pyplot as plt
months = ["Jan", "Feb", "Mar", "Apr", "May"]
visitors = [120, 135, 160, 150, 190]
signups = [12, 15, 21, 18, 26]
fig, (left, right) = plt.subplots(1, 2, figsize=(9, 3.5))
left.plot(months, visitors, marker="o")
left.set_title("Visitors")
right.bar(months, signups, color="#3776ab")
right.set_title("Sign-ups")
fig.tight_layout()
plt.show()
print("Best month:", months[signups.index(max(signups))])Press Run and the program prints Best month: May, then shows a line chart and a bar chart side by
side as one image.
How charts come back
Programs run on Python 3.14 with Matplotlib 3.11.2, on a server with no screen. Instead of opening a window, plt.show() saves each open figure as figure-1.png, figure-2.png and so on, and
the editor shows them under the output. A run can return up to 8 files,
2 MB in total.
To return a chart in another format, save it into the output directory, /tmp/outputs, which the
program finds in os.environ["OUTPUT_DIR"]. Files of these types come back: png, svg, csv, json, txt.
seaborn and pandas charts
seaborn 0.13.2 and pandas are installed, and seaborn's sample datasets load without the internet. This program
draws a box plot from the tips dataset and returns it twice, as bills.svg and as figure-1.png:
import os
import matplotlib.pyplot as plt
import seaborn as sns
tips = sns.load_dataset("tips") # installed, loads without the internet
sns.boxplot(data=tips, x="day", y="total_bill")
plt.title("Bill by day")
plt.savefig(os.path.join(os.environ["OUTPUT_DIR"], "bills.svg")) # also return an SVG
plt.show() # and the PNGA DataFrame's own df.plot() works the same way. The pandas online compiler page covers reading your own CSV.
Charts from the API
Through the API, the charts come back in the response's files field, each with its content in base64
and a link. It's free up to 100,000 runs a month.
curl -X POST https://api.onlinecompiler.io/api/run-code-sync/ \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"compiler": "python-3.14",
"code": "import matplotlib.pyplot as plt\nplt.plot([1, 3, 2])\nplt.show()\nprint(\"done\")"
}'{
"output": "done\n",
"exit_code": 0,
"files": [
{
"name": "figure-1.png",
"mime": "image/png",
"size": 14641,
"content_base64": "iVBORw0KGgo...",
"url": "https://api.onlinecompiler.io/api/files/..."
}
],
"files_truncated": false
}The API docs cover input files and returned files.
Grade a chart as data
A chart can be checked without comparing images. The oc_charts module, installed with Matplotlib,
records what each figure shows when plt.show() saves it, and oc_charts.describe() prints it as text: the titles and axis labels, the x and y values of each line,
the points of each scatter, each bar's centre and height, and the category names of a text axis. Say a student
writes this:
import matplotlib.pyplot as plt
plt.bar(["Mon", "Tue", "Wed"], [3, 5, 2])
plt.title("Orders per day")
plt.show()A stored problem runs it inside a driver that prints the chart's data after the
student's code (##CODE## is where the code goes):
##CODE##
import oc_charts
print(oc_charts.describe())That prints the chart as data, which is the test's expected output:
figure 1
axes 1
title Orders per day
xlabel
ylabel
bars vertical
x 0.0 1.0 2.0
values 3.0 5.0 2.0
xticklabels Mon Tue WedGrade it with the float checker, which compares the numbers within a tolerance and every other word
exactly, so a wrong bar height, a missing title or a different category fails while rounding noise passes.
Through run-tests, add the same two lines after the code you send. oc_charts.figures() returns the same data as a list of dictionaries, for a custom checker or your own
grading code.
What doesn't work
- Windows, animations and interactive backends: there is no display, so
plt.ion(),FuncAnimationpreviews and widgets don't show anything. - plotly and bokeh are not installed, and there is no network to install them.
- Each run gets 30 seconds and 512 MB of memory (up to 2 GB on Pro and Business), and starts fresh: nothing is kept between runs.
More for data work
- pandas online compiler: DataFrames, with a CSV from the input.
- Machine learning online compiler: scikit-learn models.
- Python online compiler: plain Python, with input.
Frequently asked questions
Why does no window open when I call plt.show()?
Programs run on a server with no screen. Here plt.show() saves each open figure as a PNG image instead, and the image appears under the output. The figures are closed afterwards, so the next plt.show() saves only the new ones.
How do I save a chart as SVG?
Save it into the output directory: plt.savefig(os.path.join(os.environ["OUTPUT_DIR"], "chart.svg")). Files saved there come back with the result if they are one of these types: png, svg, csv, json, txt.
How many charts can one run return?
Up to 8 files, 2 MB in total. Each plt.show() call saves one PNG per open figure, so a loop that shows a chart on every pass can reach the limit quickly; put several plots in one figure with plt.subplots instead.
Can I use seaborn?
Yes. seaborn 0.13.2 is installed, and its sample datasets load without the internet through sns.load_dataset, such as "tips", "penguins" or "flights". Show the chart with plt.show().
Can a chart be graded automatically?
Yes, as data rather than pixels. After the program runs, the oc_charts module prints what each figure shows: its titles and axis labels, the points of each line and scatter, the height of each bar and the category names. A grader prints oc_charts.describe() after the student's code and compares it with the float checker, so small rounding differences pass.
Does plotly work?
No. plotly and bokeh are not installed, and programs have no network to install them. Interactive charts, animations and widgets need a browser or a display, so use Matplotlib or seaborn for a static image.