Yticklabels only in large matplotlib ticks

I have a problem with yticklabels in matplotlib.

I try to make a vertical barplot (plt.barh) and then try to use the ax.set_yticklabels command. The problem that I have is that it only places tags in the main ticks! The list that I go through is 18, however it only names 10 bars!

Help me please?

+6
source share
2 answers

you need to install yticks before installing 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() 
+9
source

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 thing works for set_yticklabels ...

+1
source

Source: https://habr.com/ru/post/951787/


All Articles