First Charts with matplotlib and seaborn (Line, Bar, Hist)
Read this guide in: English · मराठी · हिंदी
Your first bar, line and histogram charts turn tables into stories. Use matplotlib and seaborn. Shop example: Mumbai bar at 120, Pune at 70. No machine learning.
Chala mitrano! Managers remember pictures. Today we draw honest first charts — bar for rank, line for trend, hist for distribution. Keep labels clear. Samajla ka?
Quick answer
Vertical first-chart path:
- Import
matplotlib.pyplotandseaborn. - Start from an aggregated table (groupby if needed).
- Bar — compare cities / clients.
- Line — trend over dates when you have them.
- Hist — distribution of likes or watches.
- Title + axis labels + one sentence takeaway.
question → aggregate → bar/line/hist → label → one message
Language: English · मराठी · हिंदी
What do I need before this guide?
- A clean-enough DataFrame and a clear question.
- Packages: matplotlib, seaborn (from the install guide).
- Course: Line and hist.
Before and after (look at the tables first)
Before — shop sales as numbers only.
After — first bar chart; Mumbai bar taller at 120.
Before: numbers only. After: bar story — Mumbai taller at 120.
matplotlib vs seaborn (beginner map)
- matplotlib — foundational plotting; Figure and Axes.
- seaborn — faster statistical charts on pandas data.
- Use both; do not fight religion wars in week one.
Course: Figure and Axes, seaborn vs matplotlib.
Bar chart — shop sales
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame({"city": ["Mumbai", "Pune"], "sales": [120, 70]})
sns.barplot(data=df, x="city", y="sales")
plt.title("Shop sales by city")
plt.ylabel("Sales")
plt.show()
What you see: Mumbai bar higher. What you say: “Mumbai leads at 120 vs Pune 70.”
Course: countplot and barplot.
Line chart — daily trend (suppose)
Suppose daily Online sales: day1 40, day2 50, day3 100 (week total story later).
daily = pd.DataFrame({"day": [1, 2, 3], "sales": [40, 50, 100]})
plt.plot(daily["day"], daily["sales"], marker="o")
plt.title("Online sales trend")
plt.xlabel("Day")
plt.ylabel("Sales")
plt.show()
Why line: order in time matters. Bars compare categories; lines show movement.
Histogram — Instagram-like likes
likes = pd.Series([80, 40, 70, 30, 90, 20])
plt.hist(likes, bins=5)
plt.title("Distribution of post likes")
plt.xlabel("Likes")
plt.ylabel("Count of posts")
plt.show()
What you see: how likes spread — not who won. Different question → different chart.
Match chart to question
| Question | Chart |
|---|---|
| Who sold more? | Bar |
| How did sales move by day? | Line |
| How are likes spread? | Hist |
| Compare categories with a second split | Bar with hue (seaborn) |
Course: Match chart to question.
Storytelling rules (classroom)
- One main message per chart.
- Label axes; include units if needed.
- Avoid chart junk — neon grids that hide the point.
- Aggregate before plotting when each row is a line item.
Course: Avoid chart junk, One-page manager story.
Axis formatting (simple)
- Readable tick labels.
- Rotate city names if they collide.
- Start bar baselines at zero for sales counts unless you have a rare, documented reason.
Course: Axis formatting simple.
seaborn quick start extras
sns.countplot— count rows per category.hue— split bars by channel.boxplot— later, for spread vs outliers.
Course: seaborn quick start, hue and boxplot.
End-to-end mini story
- Question: which city leads shop sales?
- Table: Mumbai 120, Pune 70.
- Chart: bar.
- Sentence: “Mumbai leads this extract at 120.”
- Optional next: filter Online only and redraw.
Ravindra Bagale's Tip
If you cannot say the takeaway in one spoken sentence, the chart is not ready — fix the aggregation or the title first. Samajla ka?
Practice task
- Plot the shop bar chart for Mumbai 120 / Pune 70.
- Add a Markdown takeaway sentence.
- Plot a hist of six like counts.
- Write which chart answers “who won?” vs “how spread?”.
Samajla ka? Bar for rank, line for trend, hist for spread. Label it. Say the message. Mumbai 120 should be obvious. Aata pudhe jaauya.
Frequently asked questions
matplotlib vs seaborn?
matplotlib is the base. seaborn gives faster statistical charts. Use both; the course compares them.
Which chart first?
Bar for category comparison. Line for time. Hist for distribution of one numeric column.
My bars look wrong
Check aggregation — plot groupby totals, not duplicated raw rows by mistake.
Do I need colour fireworks?
No. Clear labels beat neon themes in interviews and client work.
Where does storytelling fit?
Match chart to question — course chapter 15. One page, one manager message.
Course links?
matplotlib line/hist, seaborn bar/count, chart choice chapters.