daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Dec 14th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from matplotlib.finance import candlestick_ochl
  2.    
  3. Traceback (most recent call last):  
  4.  
  5.   File "<stdin>", line 1, in <module>  
  6.  
  7. ModuleNotFoundError: No module named 'matplotlib.finance'
  8.    
  9. import datetime
  10.  
  11. import matplotlib.dates as mdates
  12. import matplotlib.pyplot as plt
  13. import pandas as pd
  14. from matplotlib.dates import MONDAY, DateFormatter, DayLocator, WeekdayLocator
  15.  
  16. from mpl_finance import candlestick_ohlc   #  pip install mpl_finance
  17.  
  18. date1 = "2004-2-1"
  19. date2 = "2004-4-12"
  20.  
  21.  
  22. mondays = WeekdayLocator(MONDAY)        # major ticks on the mondays
  23. alldays = DayLocator()              # minor ticks on the days
  24. weekFormatter = DateFormatter('%b %d')  # e.g., Jan 12
  25. dayFormatter = DateFormatter('%d')      # e.g., 12
  26.  
  27. quotes = pd.read_csv('data/yahoofinance-INTC-19950101-20040412.csv',
  28.                      index_col=0,
  29.                      parse_dates=True,
  30.                      infer_datetime_format=True)
  31.  
  32. # select desired range of dates
  33. quotes = quotes[(quotes.index >= date1) & (quotes.index <= date2)]
  34.  
  35. fig, ax = plt.subplots()
  36. fig.subplots_adjust(bottom=0.2)
  37. ax.xaxis.set_major_locator(mondays)
  38. ax.xaxis.set_minor_locator(alldays)
  39. ax.xaxis.set_major_formatter(weekFormatter)
  40. # ax.xaxis.set_minor_formatter(dayFormatter)
  41.  
  42. # plot_day_summary(ax, quotes, ticksize=3)
  43. candlestick_ohlc(ax, zip(mdates.date2num(quotes.index.to_pydatetime()),
  44.                          quotes['Open'], quotes['High'],
  45.                          quotes['Low'], quotes['Close']),
  46.                  width=0.6)
  47.  
  48. ax.xaxis_date()
  49. ax.autoscale_view()
  50. plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')
  51.  
  52. plt.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top