I am trying to plot a simple time series with years as units in the x-axis. Unfortunately pyplot seems to think these numbers should be shown in scientific format. I have seen suggestions on Stack Overflow to change this behaviour with something like this:
plt.gca().ticklabel_format(style='plain', axis='x')
or even just
plt.ticklabel_format(style='plain', axis='x')
should be the way to go. To my surprise I noticed this does absolutely nothing on my system. It has no effect, but does not trigger any errors either. What's the deal here? I know that I can set the label strings instead but clearly this is not how it's supposed to work. Since I couldn't find any mention of this bug I wanted to check if this is a common problem.
I'm running python 2.7 on Linux.
Edit:
This is basically the code I'm using. Except the values are actually read out of a textfile.
labels = ['1989', '1990', '1991', '1992', '1993', '1994', '1995', '1996', '1997', '1998']
years = [1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998]
values = [1.4, 2.3, 4.2, 3.2, 1.2, 3.6, 9.8, 10.2, 6.1, 3.2]
plt.plot(years, values, label='Random Data')
plt.autoscale(tight=True)
plt.title('Plot of some random data')
plt.legend(loc=0)
plt.ylabel('[some unit]')
plt.xlabel('year')
plt.ticklabel_format(style='plain', axis='x') # this should work but doesn't
plt.xticks(range(1989, 1989 + len(years)), labels) # this works but is cumbersome
plt.show()
plt.savefig('beispiel.jpg')