plotly簡單繪製柱狀圖
阿新 • • 發佈:2018-12-10
程式碼:
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 為列表數值 自己根據需求填充即可