You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Pandas includes a .plot() method built directly into DataFrames and Series, providing a convenient shortcut for creating visualisations without importing Matplotlib or Seaborn explicitly. Under the hood, Pandas plotting uses Matplotlib as its default backend — so you can customise plots further using Matplotlib functions.
| Advantage | Description |
|---|---|
| Speed | One line of code to go from DataFrame to chart |
| Convenience | No need to extract columns manually |
| Integration | Plots directly from the data structure you are already working with |
| Familiar | Uses Matplotlib syntax for customisation |
import pandas as pd
import matplotlib.pyplot as plt
# DataFrame.plot(kind="chart_type", ...)
df.plot(kind="bar", x="category", y="value")
plt.show()
# Or use shortcut methods
df.plot.bar(x="category", y="value")
plt.show()
| Kind | Method | Description |
|---|---|---|
"line" | df.plot.line() | Line plot (default) |
"bar" | df.plot.bar() | Vertical bar chart |
"barh" | df.plot.barh() | Horizontal bar chart |
"hist" | df.plot.hist() | Histogram |
"box" | df.plot.box() | Box plot |
"kde" / "density" | df.plot.kde() | Kernel Density Estimate |
"area" | df.plot.area() | Area chart |
"scatter" | df.plot.scatter() | Scatter plot |
"pie" | df.plot.pie() | Pie chart |
"hexbin" | df.plot.hexbin() | Hexagonal binning plot |
import pandas as pd
import matplotlib.pyplot as plt
data = {
"Month": ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
"Revenue": [42, 45, 48, 52, 55, 61],
"Expenses": [38, 40, 42, 45, 47, 50]
}
df = pd.DataFrame(data)
df = df.set_index("Month")
ax = df.plot(figsize=(10, 5), marker="o", linewidth=2)
ax.set_ylabel("GBP (thousands)")
ax.set_title("Revenue vs Expenses")
ax.spines[["top", "right"]].set_visible(False)
ax.grid(axis="y", alpha=0.3)
plt.tight_layout()
plt.show()
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({
"Language": ["Python", "R", "SQL", "Julia", "Scala"],
"Users": [68, 18, 42, 5, 3]
})
ax = df.plot.bar(x="Language", y="Users", color="#4C72B0",
legend=False, figsize=(8, 5))
ax.set_ylabel("Usage (%)")
ax.set_title("Data Science Language Popularity")
ax.spines[["top", "right"]].set_visible(False)
plt.xticks(rotation=0)
plt.tight_layout()
plt.show()
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({
"Quarter": ["Q1", "Q2", "Q3", "Q4"],
"Product A": [120, 135, 148, 162],
"Product B": [98, 115, 132, 141],
"Product C": [65, 72, 80, 95]
})
df = df.set_index("Quarter")
ax = df.plot.bar(stacked=True, figsize=(8, 5),
color=["#4C72B0", "#DD8452", "#55A868"])
ax.set_ylabel("Revenue (GBP thousands)")
ax.set_title("Quarterly Revenue by Product (Stacked)")
ax.legend(title="Product")
plt.tight_layout()
plt.show()
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(42)
df = pd.DataFrame({
"Heights": np.random.normal(170, 10, 1000)
})
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.