1

Hi I have a dataframe with dates as index as shares as columns I want to plot a particular share using dates as x axis. The series I want to plot is : df['APPL']=

Date
2018-10-29    24.903347
2018-10-30    25.165384
2018-10-31    25.087744
2018-11-01    24.777180
...
2018-12-06    25.709999

But when I plot it out with df['APPL'].plot(use_index=True), the xasix is not showing. Then I tried plt.plot(df.index,df['APPL']), the interval of x axis is too small for it to be read.enter image description here . How can I increase the interval to show every 10 days for example?

Candice
  • 199
  • 3
  • 13

2 Answers2

1

You can rotate:

plt.xticks(rotation=90)

Demo:

plt.plot(df.index,df['APPL'])
plt.xticks(rotation=90)

After rotating, the text would be rotated to 90 degrees.

And if you prefer:

plt.plot(df.index,df['APPL'])
plt.xticks(rotation=45)

Test which you like.

U13-Forward
  • 69,221
  • 14
  • 89
  • 114
1

Found to the solution, this code changes the interval to 3 days. Kudos to @U9-Forward and @wwii for pointing out my index was not datetime format.

df.index=pandas.to_datetime(df.index)
ax = df['APPL'].plot()
# set monthly locator
ax.xaxis.set_major_locator(mdates.DayLocator(interval=3))
# set formatter
ax.xaxis.set_major_formatter(mdates.DateFormatter('%d-%m-%Y'))
# set font and rotation for date tick labels
plt.gcf().autofmt_xdate()
Candice
  • 199
  • 3
  • 13