Pandas Plotting

Pandas Tutorial

Pandas Plotting – Complete Guide (Beginner → Advanced)

Pandas has built-in plotting powered by Matplotlib, so you can visualize data with one line of code.


 1. Setup (Required)

  •  Pandas uses matplotlib behind the scenes

 2. Create Sample Data


 


 3. Basic Line Plot (Beginner)

  •  Automatically plots all numeric columns
  •  Index used as X-axis

Plot Single Column


 4. Line Plot with Custom X-Axis


 5. Multiple Line Plot

  •  Great for comparisons

 6. Bar Chart

Vertical Bar

Horizontal Bar


 7. Histogram (Data Distribution)

  •  Shows frequency distribution
  •  Interview favorite

 8. Box Plot (Outliers Detection)

 Detects:

  • Outliers

  • Median

  • Quartiles


 9. Area Plot

What This Area Plot Shows

  • X-axisyear

  • Y-axissales & profit

  • Filled areas show magnitude over time

  • alpha=0.6 → transparency so areas don’t hide each other


 Optional: Improve Readability



 10. Scatter Plot (Relationship)

 What This Scatter Plot Shows

  • X-axissales

  • Y-axisprofit

  • Each dot = one data point

  • Helps identify relationship / correlation


 Optional: Improve Clarity


 


 11. Pie Chart

 What This Pie Chart Shows

  • Each slice represents yearly sales share

  • autopct="%1.1f%%" → shows percentage

  • startangle=90 → better visual orientation


 Optional: Improve Look



 12. Plot Styling (Intermediate)


 13. Figure Size Control


 14. Plot on Specific Axes (Advanced)

  •  Overlay plots

 15. Subplots (Advanced)


 16. Save Plot to File

  •  Used in reports & automation

 17. Time Series Plot (Very Important)

  •  Pandas automatically handles dates

 18. Common Errors

1. Plot not showing
    Add plt.show()

2. Too many columns plotted
   Select columns explicitly

3. Overlapping labels
  Increase figsize


 19. Pandas vs Matplotlib

FeaturePandas PlotMatplotlib
EaseVery easyModerate
ControlLimitedFull control
Best forQuick plotsAdvanced visuals

Rule

  • Quick EDA → Pandas

  • Publication plots → Matplotlib / Seaborn


 20. Interview Questions (Must Know)

Q1: Which library Pandas uses for plotting?
 Matplotlib

Q2: Default plot type in Pandas?
 Line plot

Q3: How to plot histogram?
kind="hist"

Q4: How to plot multiple columns?
 Pass list in y


 Plot Type Cheat Sheet


 

You may also like...