Chapter 16: Pandas Plotting

Pandas plotting tutorial — written as if we are sitting together, I’m showing you the code line by line, explaining why we do things a certain way, what is realistic in real projects, and what beginners usually get wrong.

We will go from very simple to more useful & polished plots step by step.

0. Mindset before we start

Good plots in data analysis are communication tools, not just decoration.

Before writing any .plot() code, always ask yourself these three questions:

  1. What exact question should this plot answer?
  2. Who is going to look at it? (myself, colleague, manager, presentation, report)
  3. What should be the most obvious thing someone sees in 3 seconds?

Common realistic goals:

  • Show trend over time → line plot
  • Compare categories → bar / column plot
  • Show relationship between two numbers → scatter
  • Show distribution / spread → histogram, boxplot, violin
  • Show composition / proportions → stacked bar, pie (use carefully)

1. Very first simple plot (what everyone tries first)

Python

What happens? → You get a line plot, but x-axis is just 0,1,2,3,… → Not very readable.

2. Better: use index meaningfully

Python

3. Most common realistic plots – one by one

A. Line plot – evolution over time (most frequent use case)

Python

B. Bar plot – comparing categories

Python

C. Scatter plot – relationship between two variables

Python

D. Histogram – distribution of one variable

Python

E. Boxplot – compare distributions across groups

Python

Summary – Which plot when? (quick cheat sheet)

Goal Recommended plot type pandas / seaborn command example
Trend over time Line df.plot() or sns.lineplot()
Compare categories Bar / Column .plot.bar() or sns.barplot()
Relationship 2 variables Scatter / Bubble .plot.scatter() or sns.scatterplot()
Distribution / shape Histogram + KDE .plot.hist() + sns.histplot(kde=True)
Compare distributions Boxplot / Violin sns.boxplot() / sns.violinplot()
Correlation overview Heatmap sns.heatmap(df.corr(), annot=True)
Composition / proportions Stacked bar / Pie (use carefully) .plot.bar(stacked=True) or .plot.pie()

Your turn – small practice tasks

Try these on the sales DataFrame we created:

  1. Plot average daily revenue per region as a line plot
  2. Make a bar plot showing total units sold per product
  3. Create a scatter plot of units_sold vs revenue, colored by customer_rating
  4. Show boxplots of customer_rating for each region

Which one would you like to try first? Or tell me what kind of data/story you want to visualize — I’ll help you choose and build the right plot step by step.

Where do you want to go next?

  • How to make plots look much more professional (titles, legends, colors, fonts…)
  • Creating multiple plots in one figure (subplots)
  • Saving plots for reports (png, pdf, high resolution)
  • Using Seaborn more deeply (themes, palettes, easier statistics)
  • Interactive plots with Plotly (zoom, hover, export)

Just tell me what interests you most — we’ll continue slowly and practically. 😊

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *