7

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 ?

user3378649
  • 5,154
  • 14
  • 52
  • 76

2 Answers2

7

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.

Community
  • 1
  • 1
Alex Szatmary
  • 3,431
  • 3
  • 21
  • 30
3

This solution does not work for the latest version of matplotlib. Use the following code to hide the origin (0) for the y-axis:

axes.yaxis.get_major_ticks()[1].label1.set_visible(False)