How to put ticks on 2 lines in matplotlib

113 views Asked by At

How can I deal with multiple-line x ticks in matplotlib ?

Let me be more specific. I want to have a 2-line set of ticks. I managed to do something with \n already but I am not satisfied with the results because of text centering.

You can see on the example below that LUT and FF are not well centered.

Here is the image:

enter image description here

Here is part of the code:

plt.xlabel('Application')
plt.xticks(index + 5*bar_width, ('LUT~~~~~FF\nADPCM', 'LUT~~~~~FF\nAES', 'LUT~~~~~FF\nBF', 'LUT~~~~~FF\nGSM', 'LUT~~~~~FF\nDECODER', 'LUT~~~~~FF\nIDCT', 'LUT~~~~~FF\nMPEG2', 'LUT~~~~~FF\nSHA'))
plt.legend(loc=0,prop={'size':9},ncol=2)

#plot limits
# Hide the right and top spines
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
# Only show ticks on the left and bottom spines
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')
#Manually set ticks
ax.yaxis.set_ticks([100,500,1000,5000,10000,50000,100000])
minorLocator = MultipleLocator(1)
ax.xaxis.set_minor_locator(minorLocator)
#enabling grid
ax.yaxis.grid(True,linestyle='-.')
# x grid
ax.xaxis.grid(True,which='minor',linewidth=0.7,linestyle='-')
ax.xaxis.set_tick_params(which='major',width=0.5,length=18,direction='out')
ax.xaxis.set_tick_params(which='minor',width=0.7,length=30,direction='out')
ax.set_axisbelow(True)

plt.tight_layout()
plt.savefig('area.pdf')

I am not very proud of line 2 If you know what I mean.

I would like to have the same behavior as the image but with "subticks" centered with respect to their sublocation.

Thanks in advance.

0

There are 0 answers