Reputation: 2911
As I have very long string labels and some other shorter labels for one axis, I would like to place the long labels outside and the short labels inside the axis. Is that possible?
A basic example would be this:
fig, ax = plt.subplots()
ax.boxplot(np.random.randn(100), vert=0)
longlabs = ['foofoofoofoofoofoofoo']
shortlabs= ['bar']
ax.yaxis.set_ticklabels(longlabs)
Where/how to place shortlabs
at the inner side of the axis?
Upvotes: 0
Views: 1411
Reputation: 18628
ticklabels are not the same as labels. a trick that looks good on this example :
ax.yaxis.set_label_coords(.05,0.5)
ax.yaxis.set_label_text('foooooooooooooooooooooo\n\nbar')
Upvotes: 1
Reputation: 1788
You can do something like this:
longlabs = ['foofoofoofoofoofoofoo bar']
ax.yaxis.set_ticklabels(longlabs,position=(0.06,0))
But I think you should use vertical alignment for long text:
ax.yaxis.set_ticklabels(longlabs, rotation='vertical')
Hope this helps
Upvotes: 1