Python matplotlib.finance.candlestick_ohlc() Examples
The following are 5
code examples of matplotlib.finance.candlestick_ohlc().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.finance
, or try the search function
.
Example #1
Source File: chart.py From XQuant with MIT License | 7 votes |
def _candlestick_ax(df, ax): quotes = df.reset_index() quotes.loc[:, 'datetime'] = mdates.date2num(quotes.loc[:, 'datetime'].astype(dt.date)) fplt.candlestick_ohlc(ax, quotes.values, width=0.4, colorup='red', colordown='green')
Example #2
Source File: plotting.py From japandas with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _get_plot_function(self): try: from mpl_finance import candlestick_ohlc except ImportError as e: try: from matplotlib.finance import candlestick_ohlc except ImportError: raise ImportError(e) def _plot(data, ax, **kwds): candles = candlestick_ohlc(ax, data.values, **kwds) return candles return _plot
Example #3
Source File: plot_test.py From ChZhShCh with Apache License 2.0 | 5 votes |
def candle_show(self, stock_data, scatter_data): # 创建子图 fig, ax = plt.subplots(figsize=(192.0 / 72, 108.0 / 72)) mpf.candlestick_ohlc(ax, stock_data, width=self.width, colordown=self.colordown, colorup=self.colorup, alpha=1) ax.grid(True) plt.show()
Example #4
Source File: show.py From ChZhShCh with Apache License 2.0 | 5 votes |
def candle_show(self, stock_data, top_bottom_data): # 创建子图 fig, ax = plt.subplots(figsize=(192.0 / 72, 108.0 / 72)) ax.xaxis.set_major_locator(ticker.MultipleLocator(self.xaxis_cycle)) ax.xaxis.set_major_formatter(ticker.FuncFormatter(self.__format_date)) mpf.candlestick_ohlc(ax, stock_data, width=self.width, colordown=self.colordown, colorup=self.colorup, alpha=1) # title 各种设置 plt.rcParams['font.sans-serif'] = ['SimHei'] plt.rcParams['axes.unicode_minus'] = False plt.title(self.title) plt.xlabel(self.xlabel) plt.ylabel(self.ylabel) # 顶底、图例等 if len(top_bottom_data) > 0: x = [] y = [] for i in top_bottom_data: x.append(i[0]) y.append(i[1]) plt.plot(x, y, '--y*', label='分笔') plt.legend() # 展示图例 ax.grid(True) # plt.savefig('E:\PythonChZhShCh\\' + code + k_type + start_date + end_date + '.png') plt.show() # MA 画图
Example #5
Source File: CandleDrawer.py From stockflow with MIT License | 4 votes |
def draw(self, number, length = CANDLE_FIG_LENGTH): reader = Reader(number) series = [[] for x in xrange(7)] # Candle Stick candle_sticks = [] idx = -1 while True: idx +=1 row = reader.getInput() if row == None: break for i in [1, 3, 4, 5, 6]: series[i].append(float(row[i])) # matplotlib 的 candlestick_ohlc 依序放入 [編號, 收盤, 最高, 最低, 開盤] 會畫出 K 線圖 candle_sticks.append(( idx, float(row[6]), float(row[4]), float(row[5]), float(row[3]) )) bool_up_series, ma_series, bool_down_series = self._getBooleanBand(series[6]) # Draw Figure line_width = CANDLE_FIG_LINE_WIDTH fig, axarr = plt.subplots(2, sharex=True) candlestick_ohlc(axarr[0], candle_sticks[-length:], width=CANDLE_STICK_WIDTH) x_axis = range(len(series[6])) # set zorder 讓 candlestick 可以在上面 axarr[0].plot(x_axis[-length:], ma_series[-length:], c='#00ff00', ls='-', lw=line_width, zorder=-5) axarr[0].plot(x_axis[-length:], bool_up_series[-length:], c='#ff0000', ls='-', lw=line_width, zorder=-4) axarr[0].plot(x_axis[-length:], bool_down_series[-length:], c='#0000ff', ls='-', lw=line_width, zorder=-3) axarr[0].plot(x_axis[-length:], series[4][-length:], c='#ff3399', ls='-', lw=line_width, zorder=-2) axarr[0].plot(x_axis[-length:], series[5][-length:], c='#0099ff', ls='-', lw=line_width, zorder=-1) axarr[0].set_title(self._getFigTitle(number)) axarr[1].plot(x_axis[-length:], series[1][-length:], c='#000000', ls='-', lw=line_width) # set figure arguments fig.set_size_inches(FIGURE_WIDTH, FIGURE_HEIGHT) # output figure fig.savefig(CANDLE_FIG_PATH+'/'+number+'.png', dpi=FIGURE_DPI) plt.clf() plt.close('all')