Guest User

Untitled

a guest
Dec 14th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. import quandl
  2. from cycler import cycler
  3. import matplotlib
  4. import matplotlib.pyplot as plt
  5. import matplotlib.dates as mdates
  6. import datetime as dt
  7.  
  8.  
  9. quandl.ApiConfig.api_key = "Get Free Key From Quandl.com"
  10.  
  11. df_dff = quandl.get("FRED/DFF")
  12. df_iorr = quandl.get("FRED/IORR")
  13. df_ioer = quandl.get("FRED/IOER")
  14. df_gdp = quandl.get("FRED/GDP")
  15.  
  16. df_dff = df_dff[df_dff.index >= df_iorr.index.min()]
  17. df_iorr = df_iorr[df_iorr.index >= df_iorr.index.min()]
  18. df_ioer = df_ioer[df_ioer.index >= df_iorr.index.min()]
  19. df_gdp = df_gdp[df_gdp.index >= df_iorr.index.min()]
  20.  
  21. # https://matplotlib.org/gallery/ticks_and_spines/multiple_yaxis_with_spines.html
  22.  
  23.  
  24.  
  25. plt.rc('axes', prop_cycle=(cycler('color', ['r', 'c', 'm', 'y', 'k', 'b', 'g', 'r', 'c', 'm'])))
  26.  
  27. def make_patch_spines_invisible(ax):
  28. ax.set_frame_on(True)
  29. ax.patch.set_visible(False)
  30. for sp in ax.spines.values():
  31. sp.set_visible(False)
  32.  
  33.  
  34. fig, ax0 = plt.subplots()
  35.  
  36. #p0, = ax0.plot_date(df_iorr.index, df_iorr.Value, ls='dashed', tz=None, xdate=True, ydate=False, label='IORR', color='r')
  37. #ax0.yaxis.label.set_color(p0.get_color())
  38. p0 = ax0.bar(df_iorr.index, df_iorr.Value, ls='dashed', label='IORR', color='r')
  39. ax0.xaxis_date( tz=None)
  40.  
  41.  
  42. ax1 = ax0.twinx()
  43. #p1, = ax0.plot_date(df_ioer.index, df_ioer.Value, ls='dashed', tz=None, xdate=True, ydate=False, label='IOER', color='g')
  44. #ax1.yaxis.label.set_color(p1.get_color())
  45. p1 = ax1.bar(df_ioer.index, df_ioer.Value, ls='dashed', label='IOER', color='g')
  46. ax1.xaxis_date( tz=None)
  47.  
  48.  
  49. ax2 = ax0.twinx()
  50. p2, = ax0.plot_date(df_dff.index, df_dff.Value, ls='solid', tz=None, xdate=True, ydate=False, label='DFF', color='b')
  51. ax2.spines["right"].set_position(("axes", 1.2))
  52. make_patch_spines_invisible(ax2)
  53. ax2.spines["right"].set_visible(True)
  54.  
  55. ax3 = ax0.twinx()
  56. p3, = ax3.plot_date(df_gdp.index, df_gdp.Value, ls='solid', tz=None, xdate=True, ydate=False, label='GDP', color='y')
  57.  
  58. lines = [p0, p1, p2, p3]
  59. ax0.legend(lines, [l.get_label() for l in lines])
  60. plt.show()
Add Comment
Please, Sign In to add comment