Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import quandl
- from cycler import cycler
- import matplotlib
- import matplotlib.pyplot as plt
- import matplotlib.dates as mdates
- import datetime as dt
- quandl.ApiConfig.api_key = "Get Free Key From Quandl.com"
- df_dff = quandl.get("FRED/DFF")
- df_iorr = quandl.get("FRED/IORR")
- df_ioer = quandl.get("FRED/IOER")
- df_gdp = quandl.get("FRED/GDP")
- df_dff = df_dff[df_dff.index >= df_iorr.index.min()]
- df_iorr = df_iorr[df_iorr.index >= df_iorr.index.min()]
- df_ioer = df_ioer[df_ioer.index >= df_iorr.index.min()]
- df_gdp = df_gdp[df_gdp.index >= df_iorr.index.min()]
- # https://matplotlib.org/gallery/ticks_and_spines/multiple_yaxis_with_spines.html
- plt.rc('axes', prop_cycle=(cycler('color', ['r', 'c', 'm', 'y', 'k', 'b', 'g', 'r', 'c', 'm'])))
- def make_patch_spines_invisible(ax):
- ax.set_frame_on(True)
- ax.patch.set_visible(False)
- for sp in ax.spines.values():
- sp.set_visible(False)
- fig, ax0 = plt.subplots()
- #p0, = ax0.plot_date(df_iorr.index, df_iorr.Value, ls='dashed', tz=None, xdate=True, ydate=False, label='IORR', color='r')
- #ax0.yaxis.label.set_color(p0.get_color())
- p0 = ax0.bar(df_iorr.index, df_iorr.Value, ls='dashed', label='IORR', color='r')
- ax0.xaxis_date( tz=None)
- ax1 = ax0.twinx()
- #p1, = ax0.plot_date(df_ioer.index, df_ioer.Value, ls='dashed', tz=None, xdate=True, ydate=False, label='IOER', color='g')
- #ax1.yaxis.label.set_color(p1.get_color())
- p1 = ax1.bar(df_ioer.index, df_ioer.Value, ls='dashed', label='IOER', color='g')
- ax1.xaxis_date( tz=None)
- ax2 = ax0.twinx()
- p2, = ax0.plot_date(df_dff.index, df_dff.Value, ls='solid', tz=None, xdate=True, ydate=False, label='DFF', color='b')
- ax2.spines["right"].set_position(("axes", 1.2))
- make_patch_spines_invisible(ax2)
- ax2.spines["right"].set_visible(True)
- ax3 = ax0.twinx()
- p3, = ax3.plot_date(df_gdp.index, df_gdp.Value, ls='solid', tz=None, xdate=True, ydate=False, label='GDP', color='y')
- lines = [p0, p1, p2, p3]
- ax0.legend(lines, [l.get_label() for l in lines])
- plt.show()
Add Comment
Please, Sign In to add comment