I want to plot subplots base on a dataframe column's values (value of the column: "name"). I'm able to plot one plot, but when using a loop to do multiple plots, they don't show.
Plot one plot
d = {'date': ['2020-01', '2020-01', '2020-02', '2020-02'], 'id':[1, 2, 3, 4], 'name':['a', 'b', 'b', 'a'], 'type':['org', 'person', 'org', 'person']}
df = pd.DataFrame(data=d)
pivot = df[df['name'] == 'a'].groupby('date')['type'].value_counts(normalize=True).mul(100).reset_index(name='count').pivot('date', 'type', 'count')
ax = pivot.plot(kind='bar')
ax.legend(bbox_to_anchor=(1, 1), loc='upper left')
Using loop to plot subplots base on values of the column: "name"
for i, name in enumerate(names):
ax = plt.subplot(1, 2, i+1)
pivot = df[df['name'] == name].groupby('date')['type'].value_counts(normalize=True).mul(100).reset_index(name='count').pivot('date', 'type', 'count')
ax.plot(kind='bar', stacked=True, data=pivot)
ax.legend(bbox_to_anchor=(1, 1), loc='upper left')


