A stacked bar chart accumulates several component values as colored segments inside each bar. It answers questions such as how order statuses contribute to totals across product categories. section 3.3.4
The practical workflow is to reshape grouped data into a pivot table, use categories as the index, use components as columns, and plot with pandas using kind='bar' and stacked=True. section 3.3.4
Use the chart carefully:
- Compare total bar heights to see overall volume, then inspect segment sizes to study composition. section 3.3.4
- Reshape the grouped DataFrame before plotting; the example pivots product categories against order statuses and sums counts. section 3.3.4
- Improve readability with a larger figure, rotated category labels, adjusted font sizes, axis labels, a title, and a legend. section 3.3.4
- Treat a crowded or highly imbalanced chart skeptically: many categories are difficult to read, and dominant segments can hide smaller statuses. section 3.3.4 section 3.3.3
Order status by product category
After grouping merged order data by order status, English product category, and seller, pivot the counts so each category becomes a bar and each status becomes a stacked segment. The resulting visualization compares category totals while showing that delivered orders dominate across categories; smaller statuses may require further investigation. section 3.3.4
import pandas as pd
import matplotlib.pyplot as plt
# Pivot the DataFrame for the stacked bar chart
status_pivot =
status_distribution_sorted.pivot_table(
index='product_category_name_english',
columns='order_status',
values='count',
aggfunc='sum',
fill_value=0)
# Plot the stacked bar chart
plt.figure(figsize=(20, 10))
status_pivot.plot(kind='bar', stacked=True, figsize=(20, 10))
plt.xticks(rotation=90, fontsize=10)
plt.yticks(fontsize=12)
plt.xlabel('Product Category', fontsize=12)
plt.ylabel('Count of Orders', fontsize=12)
plt.title('Order Status Distribution by Product Category', fontsize=14)
plt.legend(title='Order Status', title_fontsize=12, fontsize=10,
loc='upper right')
plt.tight_layout()
plt.show()
Inspect the complete pandas and Matplotlib workflow for pivoting order-status counts and producing the stacked chart. section 3.3.4




