I would like to know how I can generate a graph that increases in width with the number of subplots.
I am trying to create a graph which contains multiple boxplots:
def create_box_plot(vals_dict, max_val):
fig = plt.figure()
ax = plt.axes()
# set axes limits and labels
plt.ylim(0, max_val)
plt.xticks(rotation=90)
counter, positionss = 1, []
# first boxplot pair
for vals in vals_dict.values():
positions = [i for i in range(counter, counter + len(vals))]
positionss.append(positions)
bp = plt.boxplot(vals, positions=positions, widths=0.6, showfliers=False)
counter += len(vals) + 1
ax.set_xticklabels(list(vals_dict.keys()))
ax.set_xticks([np.mean(positions) for positions in positionss])
buf = io.BytesIO()
plt.savefig(buf, aspect='auto', dpi=300, format='png')
buf.seek(0)
plt.close()
If I e.g. set the figzise to (20, 1), then for a large number of subplots I get a good enough looking graph:

but if I only have a few boxplots or if the labels are long the graph looks awful:
