Data Visualisation Using Plot

Pandas Basics

2 min read

Published Sep 29 2025, updated Oct 24 2025


21
0
0
0

PandasPython

What is Pandas DataFrame.plot?

Pandas provides convenient built-in plotting, which is great for quick, exploratory visualisations. However, its plotting features are more limited compared to dedicated libraries like Matplotlib, Seaborn, or Plotly.

  • Creates visualisations directly from DataFrames or Series.
  • df.plot(...) is just a wrapper around Matplotlib.
  • It creates a Matplotlib Axes object (a chart), plots the data, and returns it.
  • Matplotlib itself is the underlying engine that actually draws the chart.
  • plt.show() is a Matplotlib command → renders the plot to screen/output.
  • Automatically uses column names for labels, legends, and axes.





Syntax

DataFrame.plot(kind="line", x=None, y=None, **kwargs)

  • kind → type of plot ("line", "bar", "hist", etc.).
  • x → column name to use as x-axis.
  • y → column(s) to plot on y-axis.
  • **kwargs → passed to Matplotlib (e.g., figsize, title, xlabel, ylabel).

Since df.plot() always returns a Matplotlib Axes, you can keep customising (colors, labels, legends) with standard Matplotlib commands:

ax = df.plot(y="Sales", kind="line", color="red")
ax.set_ylabel("Pounds")
ax.set_title("Sales Trend")





Plot Types (kind)

Kind

Description

"line"

Default, line plot

"bar"

Vertical bar plot

"barh"

Horizontal bar plot

"hist"

Histogram

"box"

Box-and-whisker plot

"kde" / "density"

Kernel density estimate

"area"

Area plot

"scatter"

Scatter plot (needs x and y)

"pie"

Pie chart (works best on Series)






Example data

Example DataFrame that is used in the chart examples below.

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

# Sample dataset
df = pd.DataFrame({
    "Product": ["A", "B", "C", "D", "E"],
    "Sales": [200, 120, 340, 300, 150],
    "Profit": [50, 20, 80, 70, 25],
    "Age": [23, 45, 36, 50, 29],
    "Height": [160, 170, 175, 180, 165],
    "Weight": [55, 70, 80, 90, 60]
})





Line Plot (default)

df.plot(y="Sales", kind="line", title="Line Plot - Sales")
plt.show()

Line chart example


If you pass multiple y-columns, they’ll all be plotted together:

df.plot(y=["Sales", "Profit"], kind="line")





Bar Plot

df.plot(x="Product", y="Sales", kind="bar", title="Bar Plot - Sales")
plt.show()

Bar chart example






Horizontal Bar Plot

df.plot(x="Product", y="Sales", kind="barh", title="Horizontal Bar Plot - Sales")
plt.show()

Horizontal bar chart example






Histogram

df["Age"].plot(kind="hist", bins=5, edgecolor="black", title="Histogram - Age")
plt.show()

Histogram chart example






Box Plot

df[["Sales", "Profit"]].plot(kind="box", title="Box Plot - Sales vs Profit")
plt.show()

Box chart example






KDE / Density Plot

df["Age"].plot(kind="kde", title="KDE Plot - Age")
plt.show()

Note, for KDE charts, you also need to install the SciPy module as it uses it under the hood : pip install scipy.


KDE chart example






Area Plot

df.plot(y=["Sales", "Profit"], kind="area", alpha=0.5, title="Area Plot - Sales & Profit")
plt.show()

Area chart example






Scatter Plot

df.plot(kind="scatter", x="Height", y="Weight", title="Scatter Plot - Height vs Weight")
plt.show()

Scatter chart example






Pie Chart

df.set_index("Product")["Sales"].plot(kind="pie", autopct="%.1f%%", title="Pie Chart - Sales")
 # removes y-label
plt.ylabel("")
plt.show()

Pie chart example

Products from our shop

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Mug

Docker Cheat Sheet Mug

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Mug

Vim Cheat Sheet Mug

SimpleSteps.guide branded Travel Mug

SimpleSteps.guide branded Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - Black

Developer Excuse Javascript Mug - Black

SimpleSteps.guide branded stainless steel water bottle

SimpleSteps.guide branded stainless steel water bottle

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Dark

Developer Excuse Javascript Hoodie - Dark

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact