5

I have data.frame below

      values    years
0    24578.0  2007-09
1    37491.0  2008-09
2    42905.0  2009-09
3    65225.0  2010-09
4   108249.0  2011-09
5   156508.0  2012-09
6   170910.0  2013-09
7   182795.0  2014-09
8   233715.0  2015-09
9   215639.0  2016-09
10  215639.0      TTM

The plotted image is attached, the issue is i want years values '2007-09' to 'TTM' as xtick values in plot

The plotted image is ataached,the issue is i want years values '2007-09' to 'TTM' as xtick values in plot

0

1 Answer 1

8

One way to do this would be to access the current idices of the xticks in the x data. Use that value to select the values from df.year and then set the labels to those values:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
df.plot(ax=ax)
tick_idx = plt.xticks()[0]
year_labels = df.years[tick_idx].values
ax.xaxis.set_ticklabels(year_labels)

enter image description here

You could also set the x axis to display all years like so:

fig, ax = plt.subplots()
df.plot(ax=ax, xticks=df.index, rot=45)
ax.set_xticklabels(df.years)

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.