2019-07-30

image.png
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
%matplotlib inline

data=pd.read_csv(r'C:\Users\TAO\Desktop\python-for-data-analysis-master\examples\spx.csv',index_col=0,parse_dates=True)
data.head()
a=data['SPX'].idxmin(axis=0,skipna=True)
spx=data['SPX']
fig,ax1=plt.subplots(1,1)
data.plot(ax=ax1,style='g--')
crsis_data=[(datetime(2007,10,9),'peak of bull matket'),
            (datetime(2008,3,12),'bear fails'),
            (datetime(2008,9,15),'lehamn bankruptcy')]
for date,label in crsis_data:
    ax1.annotate(label,xy=(date,spx.asof(date)+50),xytext=(date,spx.asof(date)+240),
                arrowprops=dict(facecolor='black',width=3,headwidth=5),
                horizontalalignment='left',verticalalignment='top')
ax1.set_xlim(['1/1/2007','1/1/2011'])
ax1.set_ylim([600,1800])
ax1.set_title('important dates in 2008-2009 financial crisis')

你可能感兴趣的:(2019-07-30)