AtomLearn
DashboardGoalsGraphAchievementsReviewSign In
Data VisualizationNot Started

Bar Charts

Compare values across discrete categories

0%

Knowledge Debt detected

You can study this freely — but your score may plateau if these foundations have gaps. The Mastery badge requires them to be solid.

Explanation

Bar charts compare values across discrete categories.

python
fig, ax = plt.subplots()
categories = ['Math', 'Science', 'English', 'Art']
scores     = [85, 92, 78, 88]

ax.bar(categories, scores, color='steelblue', edgecolor='black') ax.set_title('Average Scores by Subject') ax.set_ylabel('Score') plt.show() ```

Horizontal bars (better for long category names): ``python ax.barh(categories, scores)

Grouped bars:

python import numpy as np x = np.arange(len(categories)) width = 0.35 ax.bar(x - width/2, scores_2022, width, label='2022') ax.bar(x + width/2, scores_2023, width, label='2023') ax.set_xticks(x) ax.set_xticklabels(categories) ax.legend()

pandas shortcut:

python df.groupby('dept')['salary'].mean().plot(kind='bar')

Examples

Horizontal bar chart with pandas

barh() is easier to read when category names are long

import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({'language':['Python','JavaScript','Java','C++','Go'],'popularity':[30,25,15,10,8]})

fig, ax = plt.subplots(figsize=(7,4))
ax.barh(df['language'], df['popularity'], color='coral')
ax.set_xlabel('Popularity Index')
ax.set_title('Programming Language Popularity')
plt.tight_layout()
plt.show()

Next in Data Visualization

Histograms

Continue

Unlocks