Ravindra BagaleCourses & study guides

14. Visualization with seaborn

14.3 hue and boxplot

fig, ax = plt.subplots(figsize=(8, 4))
sns.countplot(data=df, x="city", hue="status", ax=ax)
ax.set_title("City × status counts (fictional)")
plt.xticks(rotation=30, ha="right")
fig.tight_layout()
plt.show()
fig, ax = plt.subplots()
sns.boxplot(data=df, x="festival", y="amount", ax=ax)
ax.set_title("Amount spread by festival (fictional)")
plt.show()

Steps in Jupyter

  1. sns.set_theme(style="whitegrid").
  2. countplot of city.
  3. barplot of mean amount by festival.
  4. countplot with hue="status".
  5. Save one figure to figures/seaborn_city_status.png.

What you should see. Diwali mean amount higher in this tiny sample; Cancelled only under Kolhapur in the hue chart.

Ravindra Bagale's Tip

Khup students seaborn madhe loop ne matplotlib bar kartat — hue already categories sodto. DataFrame column names x= y= madhe dya. Default estimator mean asto barplot la — sum havi asel tar estimator="sum". Dhyan rakho!