Why visualise?#
A chart reveals patterns, trends and outliers in seconds that would take minutes to see in a table - and it's how most managers consume analysis.
Choosing the right chart#
| Question | Chart | matplotlib |
|---|---|---|
| How does it change over time? | Line | plt.plot() |
| How do categories compare? | Bar / horizontal bar | plt.bar() / plt.barh() |
| How are values distributed? | Histogram / box plot | plt.hist() / plt.boxplot() |
| Are two variables related? | Scatter | plt.scatter() |
| What's the share of a whole (2-5 parts)? | Pie / donut (or 100% bar) | plt.pie() |
सही chart चुनना आधा काम है:
- समय के साथ बदलाव (महीने-दर-महीने) → Line chart
- तुलना (region, product) → Bar chart (लंबे नाम हों तो horizontal bar)
- फैलाव (distribution) → Histogram / Box plot
- दो चीज़ों का संबंध (discount vs profit) → Scatter plot
- हिस्सेदारी (कुल का कितना %) → Pie (सिर्फ 2-5 हिस्से हों तो)
और chart का title ऐसा लिखें जो insight बताए - "Sales" नहीं, बल्कि "East की बिक्री 2025 में दोगुनी हुई"।
matplotlib basics#
import matplotlib.pyplot as plt
plt.figure(figsize=(8, 4)) # width, height in inches
plt.plot(x, y) # draw
plt.title("Insight as a title")
plt.xlabel("X label")
plt.ylabel("Y label")
plt.show() # display
Line chart#
Bar and horizontal bar#
Histogram and box plot#
Scatter plot#
Pie / donut#
Avoid pies with many slices, 3D charts, and dual y-axes that confuse readers. When in doubt, use a sorted bar chart.
Subplots - a mini dashboard#
pandas plotting shortcuts#
DataFrames and Series have a .plot method (built on matplotlib):
series.plot() # line
series.plot.bar() / .barh()
df.plot.scatter(x="discount", y="profit")
series.plot.hist(bins=30)
df.boxplot(column="sales", by="category")
Formatting tips#
- Big numbers: divide by 1e5 (lakh) or 1e3 and say so in the label.
plt.xticks(rotation=45)for crowded labels;plt.tight_layout()to avoid overlap.plt.bar_label(bars)adds data labels;plt.annotate()points to a specific value.- Keep colours consistent across charts (same category = same colour).
Saving charts#
plt.savefig("monthly_sales.png", dpi=150, bbox_inches="tight") # call before plt.show()
seaborn (pip install seaborn) adds beautiful statistical charts on top of matplotlib - try it on your own computer: sns.barplot, sns.heatmap, sns.boxplot. Plotly creates interactive charts for web dashboards.
Summary#
- Pick the chart for the question: line (time), bar (compare), histogram/box (distribution), scatter (relationship), pie (few-part share).
- Always add an insight title, axis labels and units.
plt.subplotsbuilds multi-chart figures; pandas.plotis a quick shortcut.- Save with
savefigfor reports and presentations.