Module 2 · Core Visualization with Matplotlib

Section 4: Business Charts (Bar, Line, and Pie Charts)

Grouped & Stacked Bars · Trend Lines · Pie & Donut · Chart Selection · Export

📊 Bar Chart Variations
  • Grouped bars: side-by-side category comparison
  • Stacked bars: part-to-whole within a category
  • Horizontal bars: ideal for long category labels
  • Data labels via ax.text() for exact values
📈 Line Charts for Trends
  • Single and multi-line time series comparison
  • Dual y-axis: ax.twinx() for different scales
  • Area fill: ax.fill_between() for cumulative views
  • Annotate periods: ax.axvspan() for highlights
🥧 Pie & Donut Charts
  • ax.pie(values, labels, autopct="%1.1f%%")
  • Explode a slice: explode=[0.1, 0, 0, 0]
  • Donut: add a white circle patch to the center
  • Best for: ≤5 categories showing composition only
🎯 Chart Selection Guide
  • Trend over time → line chart
  • Category comparison → bar chart
  • Composition / share → pie or stacked bar
  • Correlation → scatter; distribution → histogram
💾 Exporting for Business
  • PNG for reports and presentations (300 DPI)
  • SVG for scalable web and print graphics
  • PDF for vector-quality document embedding
  • bbox_inches="tight" prevents cropped labels
🧪 Lab 4 — Business Chart Suite
  • Part A: Product category grouped & stacked bar chart
  • Part B: Monthly sales trend with area fill and dual axis
  • Create a donut chart for market share composition
  • Export all charts at 300 DPI with descriptive filenames