0

I have been using this piece of code for drawing 2 subplots on the same figure. I tried many things for adding space between bars of barh in matplotlib so the labels of y-axis would be readable but I could not fix it:

plt.figure(figsize=(30, 120))
fig, axes = plt.subplots(ncols=2, sharey=True)
axes[0].barh(names, gaps, align='edge', color='green',height=1)
axes[1].barh(names, mems, align='edge', color='blue',height=1)
axes[0].invert_xaxis()
axes[0].set_yticklabels(names, fontsize=5)
axes[0].yaxis.tick_right()
for ax in axes.flat:
    ax.margins(0.01)
    ax.grid(True)
fig.tight_layout()
fig.subplots_adjust(wspace=0.37)

My current figure looks like this:

my current figure

Do you know how I can make the ylabels readable?

  • You cannot "add space" between bars. Your options are (a) Use a larger figure height, (b) use a smaller font size. – ImportanceOfBeingErnest Mar 01 '20 at 11:49
  • I have already done both as you can see in the code. It did not help and my figure looks like the image that I have uploaded. – niloofar zarif Mar 01 '20 at 18:35
  • In your code you create a figure, set its size, then create another figure, of which you do not change the size, and plot everything to the second figure. – ImportanceOfBeingErnest Mar 01 '20 at 18:54
  • Oh! now I see! If I want to change the size of the figure after the second line of this code, how should I do it? – niloofar zarif Mar 02 '20 at 03:23
  • I should think all options for setting or changing figure size are listed in [how-do-you-change-the-size-of-figures-drawn-with-matplotlib](https://stackoverflow.com/questions/332289/how-do-you-change-the-size-of-figures-drawn-with-matplotlib) – ImportanceOfBeingErnest Mar 02 '20 at 08:54

0 Answers0