Hadi Khan
Hadi Khan

Reputation: 587

Having axis ticks show fully for errorbar plot in Matplotlib

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!

Upvotes: 1

Views: 1009

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339200

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.

Upvotes: 1

Related Questions