Mathew K Analytics

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…

⬇ Download notebookOpen in Colab ↗

What you'll learn

Data

No separate download needed — the notebook creates or downloads everything it uses.

📓 Full notebook

Download .ipynb

Quick 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))
(244, 7)
   total_bill   tip     sex smoker  day    time  size
0       16.99  1.01  Female     No  Sun  Dinner     2
1       10.34  1.66    Male     No  Sun  Dinner     3
2       21.01  3.50    Male     No  Sun  Dinner     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')
<Axes: title={'center': 'Distribution of Total Bill'}, ylabel='Frequency'>
No description has been provided for this image
# 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')
<Axes: title={'center': 'Average Tip by Day'}, xlabel='day'>
No description has been provided for this image
# 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')
<Axes: title={'center': 'Total Bill vs Tip Amount'}, xlabel='total_bill', ylabel='tip'>
No description has been provided for this image
# Box plot: distribution of tips by gender
df.boxplot(column='tip', by='sex', grid=False, figsize=(6,4))
<Axes: title={'center': 'tip'}, xlabel='sex'>
No description has been provided for this image

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')
Text(0.5, 1.0, 'Restaurant Bills')
No description has been provided for this image
# 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)')
<Axes: title={'center': 'Total Bill and Tip (First 30 Rows)'}>
No description has been provided for this image
# 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')
<Axes: title={'center': 'Customer Gender Split'}>
No description has been provided for this image

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')
<Axes: title={'center': 'Lunch vs Dinner Counts'}, ylabel='time'>
No description has been provided for this image
# 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')
<Axes: title={'center': 'Mean Tip by Day and Gender'}, xlabel='day'>
No description has been provided for this image
# 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')
<Axes: title={'center': 'Tip Density by Bill Size'}, xlabel='total_bill', ylabel='tip'>
No description has been provided for this image
# 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)')
Text(0, 0.5, 'Total Bill (USD)')
No description has been provided for this image

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))
<Axes: title={'center': 'tip'}, xlabel='time'>
No description has been provided for this image
# Violin plot (extra with seaborn): smooth tip distribution by time
import seaborn as sns
sns.violinplot(x='time', y='tip', data=df, palette='pastel')
<Axes: xlabel='time', ylabel='tip'>
No description has been provided for this image

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
No description has been provided for this image

Challenge: Your Turn!#

  1. Plot the count of customers by 'smoker' status as a pie chart.
  2. Try a histogram for the 'size' column (party sizes).
  3. 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.