from datetime import datetime, timedelta
from matplotlib import pyplot as plt
from matplotlib import dates as mpl_dates
import pandas as pd
plt.style.use('seaborn')
plt.rc('figure', figsize=(12, 10))
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)
]
# print(dates)
y = [0, 1, 3, 4, 6, 5, 7]
plt.plot_date(dates, y, linestyle='solid')
# to get current figure
plt.gcf().autofmt_xdate()
# change date format
dates = [x.strftime("%b, %d %Y") for x in dates]
# %b - month
# %d - day
# %Y - year
plt.gca().set_xticklabels(dates)
# plt.set_xticklabels(dates)
plt.show()
C:\Users\batman\Anaconda3\lib\site-packages\pandas\plotting\_matplotlib\converter.py:103: FutureWarning: Using an implicitly registered datetime converter for a matplotlib plotting method. The converter was registered by pandas on import. Future versions of pandas will require you to explicitly register matplotlib converters. To register the converters: >>> from pandas.plotting import register_matplotlib_converters >>> register_matplotlib_converters() warnings.warn(msg, FutureWarning)
# example
data = pd.read_csv(r'examples/data_8.csv')
data.head()
Date | Open | High | Low | Close | Adj Close | Volume | |
---|---|---|---|---|---|---|---|
0 | 2019-05-18 | 7266.080078 | 8281.660156 | 7257.259766 | 8193.139648 | 8193.139648 | 723011166 |
1 | 2019-05-19 | 8193.139648 | 8193.139648 | 7591.850098 | 7998.290039 | 7998.290039 | 637617163 |
2 | 2019-05-20 | 7998.290039 | 8102.319824 | 7807.770020 | 7947.930176 | 7947.930176 | 357803946 |
3 | 2019-05-21 | 7947.930176 | 8033.759766 | 7533.660156 | 7626.890137 | 7626.890137 | 424501866 |
4 | 2019-05-22 | 7626.890137 | 7971.259766 | 7478.740234 | 7876.500000 | 7876.500000 | 386766321 |
data['Date'] = pd.to_datetime(data['Date'])
data.sort_values('Date', inplace=True)
price_date = data['Date']
price_close = data['Close']
plt.plot_date(price_date, price_close, linestyle='solid')
plt.gcf().autofmt_xdate()
plt.title('Bitcoin Prices')
plt.xlabel('Date')
plt.ylabel('Closing Price')
plt.tight_layout()
plt.show()