Lesson 46 · Mastering Pandas
Quick and Effective Data Visualization with Pandas plot() in Python
This lesson gives you a practical guide to fast data visualizations using pandas. You will use the famous Restaurant Tips dataset to explore, visualize, and…
- CourseMastering Pandas
- Lesson46 of 44
- Video17 min
- FormatJupyter notebook · 16 code cells
What you'll learn
Data
No separate download needed — the notebook creates or downloads everything it uses.
📓 Full notebook
Download .ipynbQuick Visualizations in Pandas: plot() Essentials#
This lesson gives you a practical guide to fast data visualizations using pandas.
You will use the famous Restaurant Tips dataset to explore, visualize, and present insights.
No prior plotting experience needed: let us turn data into visual stories!
# Suppress warnings for cleaner output
import warnings
import numpy as np
np.random.seed(42)
warnings.filterwarnings("ignore")
# Data setup (Restaurant Tips Dataset)
import seaborn as sns
df = sns.load_dataset('tips')
print(df.shape)
print(df.head(3))
Why Use Pandas plot()?#
Pandas plot() makes quick charts for you, with only one or two lines of code.
Plotting helps you spot trends, outliers, and patterns fast.
This is great for exploring data, sharing insights with team members, or knowing where to clean or analyze more.
# A first plot: histogram of total_bill column
df['total_bill'].plot(kind='hist', bins=20, color='skyblue', edgecolor='black', figsize=(8,4), title='Distribution of Total Bill')
# Bar plot: average tip by day of week
df.groupby('day')['tip'].mean().plot(kind='bar', color='coral', figsize=(6,4), title='Average Tip by Day')
# Scatter plot: total bill vs tip
df.plot(kind='scatter', x='total_bill', y='tip', color='purple', alpha=0.7, figsize=(7,5), title='Total Bill vs Tip Amount')
# Box plot: distribution of tips by gender
df.boxplot(column='tip', by='sex', grid=False, figsize=(6,4))
Understanding Axes and Layout#
Every plot has axes: X (horizontal) and Y (vertical).
You can set labels and chart size using parameters in plot().
Legends tell you what colors or shapes represent.
# Setting axis labels and chart title
ax = df['total_bill'].plot(kind='hist', bins=15, color='teal', alpha=0.8, figsize=(7,4))
ax.set_xlabel('Total Bill (USD)')
ax.set_ylabel('Number of Customers')
ax.set_title('Restaurant Bills')
# Plotting multiple columns on the same figure
df[['total_bill', 'tip']].plot(kind='line', figsize=(10,4), title='Total Bill and Tip (First 30 Rows)')
# Pie chart: proportion of male and female customers
df['sex'].value_counts().plot(kind='pie', autopct='%1.1f%%', startangle=90, colors=['#66b3ff','#ff9999'], figsize=(5,5), ylabel='', title='Customer Gender Split')
Customizing Styles Quickly#
Pandas plot() is built on Matplotlib, letting you pass colors, alpha (transparency), size, and more.
Try out different palettes to make charts clearer or match your brand.
You can use kind='barh' for horizontal bars, or change marker styles in scatter plots.
# Horizontal bar plot: total customers per time of day
df['time'].value_counts().plot(kind='barh', color='goldenrod', figsize=(6,3), title='Lunch vs Dinner Counts')
# Grouped bar plot: tips by day and gender
pivot = df.pivot_table(values='tip', index='day', columns='sex', aggfunc='mean')
pivot.plot(kind='bar', figsize=(8,5), title='Mean Tip by Day and Gender', colormap='Set2')
# Exploring relationships: hexbin plot (advanced scatter density)
df.plot(x='total_bill', y='tip', kind='hexbin', gridsize=20, cmap='Blues', sharex=False, figsize=(7,5), title='Tip Density by Bill Size')
# Time-based plotting: fake time series with sample data
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
date_range = pd.date_range(start='2023-01-01', periods=244, freq='D')
tips_by_date = pd.DataFrame({'date': date_range, 'total_bill': np.random.choice(df['total_bill'], size=244)})
tips_by_date.set_index('date')['total_bill'].plot(title='Simulated Daily Total Bill', figsize=(10,3))
plt.xlabel('Date')
plt.ylabel('Total Bill (USD)')
Mini-Project: Charting Insights#
Let us quickly try a real data story: Are dinner tips higher than lunch tips at this restaurant?
We will compare tip distributions and try to visualize the answer.
# Boxplot: tips by lunch vs dinner
df.boxplot(column='tip', by='time', grid=False, figsize=(7,4))
# Violin plot (extra with seaborn): smooth tip distribution by time
import seaborn as sns
sns.violinplot(x='time', y='tip', data=df, palette='pastel')
Best Practices: Quick Visualization Tips#
- Always label your axes and add titles for clarity.
- Check your data types: numbers for line, bar, or box. Text for counts or pie.
- Use color or marker shape to show different groups.
- Start with the simplest chart that matches your question.
# Troubleshooting: What if plt.show() is needed?
import matplotlib.pyplot as plt
ax = df['tip'].plot(kind='hist', bins=10)
plt.show() # Just in case charts do not appear automatically
Challenge: Your Turn!#
- Plot the count of customers by 'smoker' status as a pie chart.
- Try a histogram for the 'size' column (party sizes).
- Find what other comparisons you can make with bar or box plots.
Pause the video, experiment, and share your findings in the comments!
Wrap-up: Quick Viz Mastery#
You just learned practical pandas plot() skills: histograms, bar, pie, scatter, boxplots, and more.
Use these tools for fast exploration and crystal-clear insights on your own data.
For more lessons, remember to subscribe and keep learning with us on YouTube!
Found this useful?
All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.



