Charts with Matplotlib
A chart often shows in a second what a table hides. Pandas can draw charts straight from a DataFrame using Matplotlib.
A good chart makes the main point obvious in seconds, which is why reports and presentations rely on them. Choose the chart type by the question, label everything, and give it a title that states the finding.
Example
A line chart over time
Example
Which chart?
- Bar - compare groups (cities, products)
- Line - change over time
- Histogram (
kind="hist") - how values spread out (order sizes) - Scatter - is one number linked to another (price vs quantity)?
- Avoid pie charts with many slices - bars are easier to read
Always label the axes with units, start bar charts at zero, and give the chart a title that says the point: "Delhi brings the most revenue" beats "Chart 1". For interactive charts, try Plotly; for quick statistics charts, Seaborn.
Key points
- Bar to compare, line for trends, histogram for spread.
- Label axes with units and use clear titles.
- savefig saves charts as images.
📝 Test yourself
1. Which chart is best for change over time?
2. What does plt.savefig do?
3. Fill in the kind for a horizontal bar chart:
series.plot(kind="")
