0
votes

I am trying to plot a graph using Matplotlib using the following code:

fig, axs = plt.subplots()
axs.set_xlim([1,5])
axs.grid()
axs.errorbar(plot1_dataerr[1],range(len(plot1_dataerr[1])),xerr = plot1_dataerr[2], fmt = 'k o')
axs.yaxis.set_ticks(np.arange(len(plot1_dataerr[1])))
axs.set_yticklabels(plot1_dataerr[0])

The variable plot1_dataerr contains the labels for the data as its 0th element, the actual means as the 1st element and the half-length of the error bars as the second element. When I run this code (along with the exact data) I get the following: The Actual Plot

However as you can see some of the ticks on the y-axis are cut off, they should all start with 'vegetable based side dishes'. Does anyone know what I should change so that everything fits. I don't mind if some of the labels need to occupy 2 lines.

Thanks in advance!

1
Are you able to run a plt.tight_layout() after plotting? I find that that usually fixes my axes label problems the easiest, but sometimes it's not an option because I need consistent sizes for the axes display. - KevinG

1 Answers

1
votes

You probably need to increase the left margin. For automatic adjustment, use

fig.tight_layout()

Else, start with

fig.subplots_adjust(left=0.4)

and decrease the value until you are happy with the result.