In [1]:
import pandas as pd
from datetime import datetime, timedelta
from matplotlib import pyplot as plt
from matplotlib import dates as mpl_dates
In [2]:
dates = [
    datetime(2019, 5, 24),
    datetime(2019, 5, 25),
    datetime(2019, 5, 26),
    datetime(2019, 5, 27),
    datetime(2019, 5, 28),
    datetime(2019, 5, 29),
    datetime(2019, 5, 30)
]
y = [0, 1, 3, 4, 6, 5, 7]
In [8]:
plt.style.use('seaborn')

plt.plot_date(dates,y,linestyle='solid')

#get current figure #for rotating dates
plt.gcf().autofmt_xdate()

#formatting date, default is year-month-date
date_format = mpl_dates.DateFormatter('%d %b, %Y')

#get current axis
plt.gca().xaxis.set_major_formatter(date_format)

plt.tight_layout()

plt.show()
In [14]:
#real world example #bitcoin value for 2week

data = pd.read_csv('data.csv')

#coverting date string to datetime using pandas
data['Date']= pd.to_datetime(data['Date'])
#sorting datetime
data.sort_values('Date', inplace=True)

price_date = data['Date']
price_close = data['Close']
In [15]:
plt.plot(price_date, price_close,linestyle='solid')

plt.title('Bitcoin Prices')
plt.xlabel('Date')
plt.ylabel('Closing Price')

plt.gcf().autofmt_xdate()

plt.tight_layout()

plt.show()