I have a problem regarding yticklabels in matplotlib.
I' m trying to make a vertical barplot (plt.barh) and then trying to use ax.set_yticklabels command. The problem that I have is that it only puts the labels at the major ticks! The list that I'm passing is of length 18, however it only labels 10 of the bars!!
Help please?
you need to set yticks
before you set yticklabels
:
from numpy import *
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x=random.uniform(0,5,size=5)
#plot
ax.barh(arange(len(x)),x,1)
#set ticks
T=arange(len(x))+0.5
ax.set_yticks(T)
#set labels
labels=['a','b','c','d','e']
ax.set_yticklabels(labels)
plt.show()
You can use set_yticks
, but passing the argument minor
True
or False
:
majorticks = [1., 2., 3.]
minorticks = [1.5, 2.5]
ax.set_yticks( minorticks, minor=True )
ax.set_yticks( majorticks, minor=False ) # The default in version 1.3.0
The same works for set_yticklabels
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With