Why is my X-axis ticks showing Negative values when the Xaxis values range from 43990 - 44003.
import matplotlib.pyplot as plt
x=[44000, 44001, 44002, 44003, 43990, 43991, 43992, 43993, 43994, 43995, 43996, 43997, 43998, 43999]
y=[8, 5, 3, 1, 1, 3, 4, 10, 4, 11, 4, 10, 17, 19]
plt.bar(x,y)
plt.show()
I am seeing the following output. I was expecting x-axis to range from 43990 - 44003
I have tried this on a couple of machines, all showing similar strange behaviour on recent versions of python and matplotlib (tried a few different versions)
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19) [GCC 7.2.0] on linux
Python 3.4.3 (default, Nov 17 2016, 01:08:31)
Strangely enough many trivial toy example x and y arrays are giving me expected figures.
For e.g the follwowing snippet shows the expected graph with correct x-axis tick labels
x=[20,30,90,70, 50, 60, 80, 70]
y=[3,2,5,10, 3, 9, 7, 6]
plt.bar(x,y)
plt.show()
What obvious thing am i missing here ?
You need to disable the offset:
plt.ticklabel_format(useOffset=False)
Another option would be to input custom tick labels:
plt.bar(x, y, tick_label=x)