I have the following code to create a 9x3 plot of 27 subplots:
fig, axes = plt.subplots(9,3,figsize=(30,80))
for ax, df in zip(axes.flat, [district_1_change, district_2_change, district_3_change,
district_4_change, district_5_change, district_6_change,
district_7_change, district_8_change, district_9_change,
district_10_change, district_11_change, district_12_change,
district_13_change, district_14_change, district_15_change,
district_16_change, district_17_change, district_18_change,
district_19_change, district_20_change, district_21_change,
district_22_change, district_23_change, district_24_change,
district_25_change, district_26_change, district_27_change
]):
df[['DEM', 'REP', 'CON', 'WOR',
'IND', 'GRE', 'WEP', 'REF', 'OTH', 'BLANK']].plot.bar(ax=ax,
legend=False,
# figsize=(8, 6),
color=['xkcd:blue',
'xkcd:red',
'xkcd:dark red',
'xkcd:light blue',
'xkcd:purple',
'xkcd:green',
'xkcd:pink',
'xkcd:lilac',
'xkcd:orange',
'xkcd:brown'])
plt.tight_layout();
I want to add titles to each subplot. I have consulted this previous SO question but when I try to do something like:
ax = plt.subplot("931")
ax.set_title("District 1")
the data in that subplot is then erased, however, the title shows up. I would like the data and the title to both show.