zoukankan      html  css  js  c++  java
  • plotly简单绘制柱状图

    代码:

    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 为列表数值 自己根据需求填充即可

  • 相关阅读:
    js计算两个时间相差天数
    享元模式
    外观模式
    组合模式
    装饰者模式
    桥接模式
    适配器模式
    元素量词 ? + *
    linux安装使用7zip
    linux shell使用别名,切换当前目录
  • 原文地址:https://www.cnblogs.com/bigtreei/p/10095840.html
Copyright © 2011-2022 走看看