0

Hi I'm very new to Python, and I'm trying to fix the labels because they overlap, (as seen in the picture). I figured the hspace and the wspace is the columns, but I'm not sure exactly how to adjust everything else in the labels, I don't want to mess with the x axis. Is there a way to make this plot look clearer?

Here's what I have:

_, axes = plt.subplots(nrows=6, ncols=6, sharex=True)
plt.suptitle('mean activity duration by time of day')
plt.subplots_adjust(hspace=0.5, wspace=0.5)
 
for ax, (activity, df) in zip(axes.ravel(), df_all.groupby('e')):
    (df.groupby('f')
                  .d
                  .mean()
                  .plot(ax=ax,
                        kind='bar',
                        title=activity,
                        xlabel='time'))

6 x 6 bar graph:

6 x 6 bar graph

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
  • Aside from the answer in the duplicate, you would probably be better off using `seaborn.catplot` with `kind='bar'` and using the `col` and `col_wrap` parameter. It would mostly replace your entire code with 1 line. – Trenton McKinney May 25 '21 at 16:00

2 Answers2

0

You can try to use plt.tight_layout, adjusts subplot params so that the subplot(s) fits in to the figure area

drauedo
  • 641
  • 4
  • 17
0
  • Use constrained_layout.
  • use a larger figure size so your titles are not larger than your axes
  • use a smaller font size for the titles.

You can use tight_layout if you prefer, but constrained_layout is more flexible.

Jody Klymak
  • 4,979
  • 2
  • 15
  • 31
  • Hi! Thank you for your comment :) How would I go about using larger figure sizes? Should/can I separate the graphs? (instead making 36 individual plots instead of 36 in one figure) – I_will_learn May 25 '21 at 15:17
  • The subplots command takes a figsize argument in inches. – Jody Klymak May 25 '21 at 15:25