Bar Plots in Pandas & Seaborn – Best Practices for Categorical Data 2026
Bar plots are one of the most effective ways to visualize and compare categorical data. In 2026, combining Pandas’ simple .plot(kind="bar") with Seaborn’s barplot() and countplot() gives you both quick insights and publication-quality visualizations.
TL;DR — When to Use Which Bar Plot
df.plot(kind="bar")– Quick bar chart from Pandassns.barplot()– Statistical bar plots with confidence intervalssns.countplot()– Simple frequency counts
1. Basic Bar Plot with Pandas
import pandas as pd
import matplotlib.pyplot as plt
# Create a small demo file so this example runs as-is
# (in your project, sales_data.csv is your real export)
import numpy as np
rng = np.random.default_rng(42)
n = 60
pd.DataFrame({
"order_date": pd.date_range("2026-01-01", periods=n, freq="3D"),
"customer_id": rng.integers(101, 121, n),
"customer_name": rng.choice([" ana", "ben ", "chen", "dana"], n),
"product_id": rng.integers(1, 9, n),
"region": rng.choice(["North", "South", "East", "West"], n),
"category": rng.choice(["Electronics", "Computers", "Books", "Home"], n),
"payment_method": rng.choice(["card", "cash", "wallet"], n),
"segment": rng.choice(["consumer", "business"], n),
"quantity": rng.integers(1, 6, n),
"amount": rng.uniform(50, 2500, n).round(2),
"discount": rng.choice([0.0, 0.05, 0.1, 0.2], n),
}).assign(
price=lambda d: (d["amount"] / d["quantity"]).round(2),
profit=lambda d: (d["amount"] * rng.uniform(0.05, 0.3, n)).round(2),
).assign(
ship_date=lambda d: d["order_date"] + pd.Timedelta(days=2),
status=lambda d: np.where(d["amount"] > 2000, "priority", "standard"),
).to_csv("sales_data.csv", index=False)
df = pd.read_csv("sales_data.csv")
# Total sales by region
sales_by_region = df.groupby("region")["amount"].sum()
sales_by_region.plot(
kind="bar",
figsize=(10, 6),
color="skyblue",
edgecolor="black"
)
plt.title("Total Sales by Region")
plt.ylabel("Sales Amount")
plt.xlabel("Region")
plt.xticks(rotation=0)
plt.show()
2. Professional Bar Plots with Seaborn
import seaborn as sns
plt.figure(figsize=(10, 6))
# Bar plot with mean and confidence interval
sns.barplot(
data=df,
x="region",
y="amount",
estimator="sum", # or "mean", "median", etc.
errorbar=("ci", 95), # 95% confidence interval (replaces the old ci=95)
hue="region", # palette now needs a hue column
palette="Blues_d",
legend=False
)
plt.title("Total Sales by Region with Confidence Intervals")
plt.ylabel("Total Sales Amount")
plt.show()
3. Count Plot vs Bar Plot
# Count of transactions by category
plt.figure(figsize=(10, 6))
sns.countplot(
data=df,
x="category",
order=df["category"].value_counts().index
)
plt.title("Number of Transactions by Category")
plt.xticks(rotation=45)
plt.show()
# Average sales by category
plt.figure(figsize=(10, 6))
sns.barplot(
data=df,
x="category",
y="amount",
estimator="mean"
)
plt.title("Average Sales Amount by Category")
plt.show()
4. Best Practices in 2026
- Use
sns.barplot()when you need statistical estimates and confidence intervals - Use
df.plot(kind="bar")for very quick exploratory plots - Use
sns.countplot()when you want to show frequencies/counts - Always sort categories by value using
order=or.sort_values() - Rotate x-labels with
plt.xticks(rotation=45)when labels are long - Use meaningful color palettes (e.g.,
"Blues_d","viridis","Set2")
When to Use a Bar Plot
Bar plots compare a numeric value across categories, such as sales by region or average rating by product. pandas plot.bar draws values you have already aggregated, while seaborn barplot aggregates for you and shows an uncertainty interval for each bar.
Sort bars by value unless the categories have a natural order, start the value axis at zero, and use horizontal bars when labels are long. In seaborn 0.13 and later, use errorbar= instead of the old ci= argument.
Worked Example: Aggregated and Raw Data
We draw totals with pandas and averages with confidence intervals using seaborn.
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame({
"region": ["North", "South", "East", "West"] * 3,
"sales": [120, 80, 60, 150, 130, 75, 65, 140, 110, 85, 70, 160],
})
totals = df.groupby("region")["sales"].sum().sort_values(ascending=False)
print(totals)
fig, axes = plt.subplots(1, 2, figsize=(10, 4))
totals.plot.bar(ax=axes[0], title="Total sales", rot=0)
sns.barplot(data=df, x="region", y="sales", hue="region", errorbar=("ci", 95),
order=totals.index, legend=False, ax=axes[1])
axes[1].set_title("Mean sales with 95% CI")
fig.tight_layout()
West leads in total sales, and the seaborn chart shows its mean with an interval built from the three underlying values. Reusing the sorted index as order keeps both charts in the same sequence.
Common Mistakes
- Using bar plots for continuous time series.
- Starting the value axis above zero.
- Leaving bars unsorted with no natural order.
- Using the deprecated ci= argument in seaborn.
Quick Summary
- Bar plots compare values across categories.
- pandas plots pre-aggregated values; seaborn aggregates.
- Sort bars and start at zero.
- Use errorbar= for uncertainty intervals.
Conclusion
Bar plots are excellent for comparing categories and showing totals or averages. In 2026, start with Pandas .plot(kind="bar") for quick checks, then switch to Seaborn’s barplot() and countplot() for more insightful and visually appealing results. Always sort your categories and add clear titles and labels to make your bar plots truly effective for analysis and presentation.
Next steps:
- Create bar plots showing total sales and average sales by region and by category from your current dataset