0

I'm trying to graph different quarters' worth of economic data. I have a pandas dataframe and I imported the csv like:

unemployment_data = pd.read_csv("unemploymentbystate.csv")
unemployment_data.set_index('Date')
unemployment_data.plot()

But how do I get the 21 ticks to show on the X axis as Q1 2015 through q1 2020 iteratively? (I.e. q2 2015, q3 2015...up to q1 2020)?

right now it only shows random intervals of 0.0, 2.5, 5.0, 7.5 up to 20 on the x axis.

Thank you!

enter image description here

enter image description here

dbs5
  • 133
  • 2
  • 9
  • You can set the x-Ticklabels using https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.set_xticklabels.html – MalteHerrmann Apr 24 '20 at 20:03
  • Thanks for the reply! Can you kindly guide me to use the following line to "translate" 0.0 and 2.5 (and so on...) into the q1 2015, q2 2015, etc.? Axes.set_xticklabels(self, labels, fontdict=None, minor=False, **kwargs) – dbs5 Apr 24 '20 at 20:08
  • You will find what you need here: https://stackoverflow.com/questions/21910986/why-set-xticks-doesnt-set-the-labels-of-ticks – MalteHerrmann Apr 24 '20 at 20:13

1 Answers1

3

set_index() by default returns a new dataframe, not modify your original. You can do, without set_index:

unemployment_data.plot(x='Date')

Or,

unemployment_data = unemployment_data.set_index('Date')
unemployment_data.plot()
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74