How to use the Matplotlib Chart Code Generator
- 1. Choose a chartLine, area, bar, horizontal bar, grouped, stacked, pie, donut, scatter or histogram.
- 2. Add dataPaste a small table (labels then values) or name a CSV and its columns.
- 3. Style and copySet titles, colours, style, size and file name, then copy or download the script.
What the code includes
The script uses the recommended fig, ax = plt.subplots() style. It sets the title and axis labels, removes the top and right borders, adds light grid lines and, for bars, value labels with ax.bar_label. Grouped bars are offset with NumPy, stacked bars carry a running bottom, and pie and donut charts keep a round shape. A legend appears when there's more than one series. Finally fig.tight_layout() and savefig(..., dpi=150, bbox_inches="tight") save it without clipped labels. Pasted data is written into the script; a CSV source reads with pandas.
Worked example
The default is a grouped bar chart of monthly enrolments for Python and Data Analytics from April to September (6 labels × 2 series), with the orange-and-navy palette. The result is a 28-line script that saves chart.png. The page also shows a quick sketch so you can check the layout before running it.
How we checked it
- All 10 chart types were generated with pasted data and with a CSV source, across four palettes and five styles.
- All 20 scripts ran with Matplotlib and saved a picture.
bar_labelneeds Matplotlib 3.4 or later; the seaborn style name needs Matplotlib 3.6 or later.- Values are written into the script as plain numbers, so ₹ symbols and commas in pasted data are removed first.
Choosing a chart
Use a line chart for change over time, bars to compare categories, grouped bars to compare two series side by side, and stacked bars to show parts of a total. Keep pie and donut charts to a handful of slices, use scatter to show a relationship between two numbers, and use a histogram to see how values are spread.
Frequently asked questions
Where does the chart appear?
plt.show() opens it in a window (or below the cell in Jupyter), and it's also saved to the file name you chose.
Can I use my Excel data?
Copy the cells from Excel and paste them into the data box. Pasted tabs work as well as commas.
Is the Matplotlib chart code generator free?
Yes. You can open the Matplotlib chart code generator, load files and set every option without signing up. When you generate code for the first time, we ask once for your name and WhatsApp number; after that it, and every other Uncodemy tool, opens straight away.