Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we hide the first zero in axes matplotlib

I am trying to plot histogram.

plt.bar([1,2,3], [4,5,6],color="r",align="center")

I don't wanna plot the zero in the beginning of the axes. This ridiculous way to do it.

plt.yticks(range(len([1,2,3])),["None"]+[1,2,3])

Is there any good way to do that ?

like image 221
user3378649 Avatar asked Feb 11 '23 08:02

user3378649


1 Answers

This is similar to this question. There isn't a much less ridiculous way to do what you're trying to do. This snippet, adapted from the linked question,

ax = plt.gca()
xticks = ax.xaxis.get_major_ticks() 
xticks[0].label1.set_visible(False)

should do the trick.

like image 110
Alex Szatmary Avatar answered Feb 14 '23 05:02

Alex Szatmary