代码:
import plotly.offline as pltoff import plotly.graph_objs as go def bar_charts(name="bar_charts.html"): dataset = {'amount price avg_cost':['set_slippage / no_slippage'], 'y1':amount, # amount 'y2':price, # price 'y3':avg_cost} # avg_cost data_g = [] # amount tr_y1 = go.Bar( x = dataset['amount price avg_cost'], y = dataset['y1'], name = 'amount') data_g.append(tr_y1) # price tr_y2 = go.Bar( x = dataset['amount price avg_cost'], y = dataset['y2'], name = 'price') data_g.append(tr_y2) # avg_cost tr_y3 = go.Bar( x = dataset['amount price avg_cost'], y = dataset['y3'], name = 'avg_cost') data_g.append(tr_y3) layout = go.Layout(title="设置滑点/不设置滑点模拟盘对比", xaxis={'title':'amount price avg_cost'}, yaxis={'title':'相除后的值'}) fig = go.Figure(data=data_g, layout=layout) # pltoff.plot(fig, filename=name) # 保存成 html plotly.offline.init_notebook_mode() plotly.offline.iplot(fig,filename='basic-scatter') if __name__=='__main__': bar_charts()
# amount price avg_cost 为列表数值 自己根据需求填充即可