How do I set up the values for the x axis in matpl

2019-03-05 08:58发布

问题:

plt.figure(figsize=(15,5))
plt.plot(data['Unemployment Rate'])
plt.axis([1948,2017,0,15])
plt.show()

These code returned an empty graph.

The table contains 2 columns, data['Year'] and data['Unemployment Rate'].

The year is between 1948 and 2017.

What I am trying to accomplish is to generate a graph for the unemployment rate and use the values in data['Year'] as the value of the x axis.

回答1:

If you want to plot y against x, you need to inform matplotlib to do so.

plt.plot(x,y)

If instead you only call plt.plot(y), matplotlib would not know that you want to plot against the x data. Instead it would take the numbers 0,1,...N-1 to plot against.