Pandas VisualizationΒΆ
Pandas integrates directly with Matplotlib through the .plot() method on DataFrames and Series, making it possible to create publication-quality charts with minimal code. Instead of manually extracting arrays and calling Matplotlib functions, you can generate plots directly from your data structures.
This notebook covers line plots for trends over time, horizontal bar charts (including stacked bars for composition analysis), scatter plots for examining relationships between two variables, histograms for distribution analysis, box plots for identifying outliers and spread, area charts for cumulative comparisons, and pie charts for proportional breakdowns. Each plot type serves a different analytical purpose, and choosing the right visualization is as important as the analysis itself.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.read_csv(r"C:\Users\alexf\OneDrive\Documents\Pandas Tutorial\Ice Cream Ratings.csv")
df = df.set_index('Date')
df
print(plt.style.available)
plt.style.use('classic')
df.plot(kind = 'line', title = 'Ice Cream Ratings', xlabel = 'Daily Ratings', ylabel = 'Scores')
df.plot.barh(stacked = True)
df.plot.scatter(x = 'Texture Rating', y = 'Overall Rating', s = 500, c = 'Yellow')
df.plot.hist(bins = 10)
df.boxplot()
df.plot.area(figsize = (10,5))
df.plot.pie(y='Flavor Rating',figsize=(10,10))