Bar chart
A bar chart compares a number across categories using bar length. Because length is read from the baseline, the value axis should start at zero.
When to use it
- You compare totals, counts or averages across categories.
- The categories have no natural order, or a short one.
Watch out: For means of a few measurements, bars hide the spread. Show the individual points or a box plot.
Ask for it in pltchat
Upload your file and type something like:
"bar chart of total sales by product, sorted descending"
pltchat writes the loader and the plot for your columns, runs it in your browser and shows you the code.
The matplotlib code
Self-contained with example data; swap in pd.read_csv(...) or
pd.read_excel(...) for your own file.
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({"product": ["Alpha", "Beta", "Gamma", "Delta", "Epsilon"],
"sales": [320, 185, 410, 95, 240]})
df = df.sort_values("sales", ascending=False)
fig, ax = plt.subplots(figsize=(6.4, 4))
ax.bar(df["product"], df["sales"], color="C0")
ax.set_ylabel("Units sold")
ax.set_title("Sales by product")
ax.bar_label(ax.containers[0], padding=2)
ax.spines[["top", "right"]].set_visible(False)
plt.tight_layout()
plt.show()
Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.