def get_ohlc(df,up_color=None,down_color=None,theme=None,layout=None,**kwargs): layout=getLayout(theme=theme) if not layout else layout ohlc=['open','high','low','close'] if not theme: theme = auth.get_config_file()['theme'] c_dir=ta._ohlc_dict(df) args=[df[c_dir[_]] for _ in ohlc] args.append(df.index) fig=ff.create_ohlc(*args,**kwargs) ohlc_bars={} ohlc_bars['data']=fig['data'] ohlc_bars['layout']=fig['layout'] data=ohlc_bars['data'] if up_color: data[0]['line'].update(color=normalize(up_color)) if down_color: data[1]['line'].update(color=normalize(down_color)) ohlc_bars['layout']['hovermode']='closest' ohlc_bars['layout']=merge_dict(layout,ohlc_bars['layout']) return ohlc_bars
def create_ohlc(*args, **kwargs): FigureFactory._deprecated('create_ohlc') from plotly.figure_factory import create_ohlc return create_ohlc(*args, **kwargs)
import plotly as py # 导入plotly库并命名为py import plotly.figure_factory as ff # 导入plotly工具箱库中的图像工厂方法并命名为FF # -------------pre def pyplt = py.offline.plot import pandas as pd df = pd.read_csv(r'dat/appl.csv', index_col=['date'], parse_dates=['date']) fig = ff.create_ohlc(df.open, df.high, df.low, df.close, dates=df.index) pyplt(fig, filename=r'tmp/first_ohlc_old.html')