Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/just-cameron/misc-python. All my Python code for class or other things.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import matplotlib.pyplot as mpimport matplotlib.dates as mdimport pandas as pdimport datetime as dt
#Grab pound/USD informationfx = pd.read_pickle("data.csv")fx = fx[["GBPUSD", "GBPEUR", "KY"]]fx2 = fx.loc["2013-01-01":] # Remove un-needed datafx3 = fx2[["GBPUSD", "GBPEUR"]]
#Make significant datesdates = [dt.date(2013,1,23), dt.date(2016,1,22), dt.date(2016,6,23), dt.date(2016,6,24), dt.date(2016,7,13)]
#Labels for annotationlabels = ["Cameron promises referendum", "Conservative party wins", "Referendum date selected", "Referendum held", "Results announced", "Cameron resigns, May steps in"]
#fx2.plot()
fig, ax = mp.subplots()
ax.plot(fx3['GBPUSD'], label = "GBP/USD")ax.plot(fx3['GBPEUR'], label = "GBP/EUR")
mp.plot(fx)labi = 0for i in range(0,len(fx2)): if fx2["KY"][i] == 1: ax.annotate(labels[labi], xy = (fx2.index[i], fx2['GBPUSD'][i]), textcoords='data', xytext= (fx2.index[i], fx2['GBPUSD'][i]+0.1), arrowprops=dict(arrowstyle='->')) labi = labi + 1
'''#Place annotations here for all i in dates. The following code is suggestedfrom http://stackoverflow.com/questions/11067368/annotate-time-series-plot-in-matplotlib
for i in range(0,5): ax.annotate(labels[i], (md.date2num(dates[i]), fx2.loc[str(dates[i])]), textcoords='data', xytext= (dates[i],fx2.loc[str(dates[i])] + 0.05), arrowprops=dict(arrowstyle='-|>'))'''mp.legend()mp.ylabel("GBP vs. Euro and Dollar")mp.xlabel("Date")mp.title("Exchange Rates on Key Brexit Dates")mp.xticks(rotation=45)mp.grid(True)
#Show the plot we've made.mp.savefig("timeline.png")mp.show()