nukedfridge
nukedfridge

Reputation: 23

How to get x axis labels for time series? (python, pandas)

I am trying to plot a time series dataframe in pandas. The plot looks fine, but there are no labels on the x-axis:

picture of the timeseries plot

Can anybody suggest something on this? My code

import pandas as pd  
from pandas import Series
import matplotlib.pyplot as plt

df = pd.read_csv("coindeskbpi.csv", parse_dates =True , index_col = 'Date', 
dayfirst=True)

df.head()

df.plot()
plt.show()

The data looks like this

                        Open     High      Low    Close
Date                                                   
2017-11-01 00:00:00  6447.67  6750.17  6357.91  6750.17
2017-11-02 00:00:00  6750.17  7355.35  6745.96  7030.00
2017-11-03 00:00:00  7030.00  7454.04  6942.29  7161.45
2017-11-04 00:00:00  7161.45  7503.72  6994.88  7387.00
2017-11-05 00:00:00  7387.00  7601.53  7297.58  7382.45
<class 'pandas.core.frame.DataFrame'>

and has 94 entries.

Upvotes: 2

Views: 739

Answers (1)

Joe
Joe

Reputation: 12417

Try in this way:

df = pd.read_csv("coindeskbpi.csv", sep=',') #or the sep you are using
df.set_index('Date', inplace=True)
df.plot()
plt.show()

enter image description here

Upvotes: 2

Related Questions