【问题标题】:How can I make three plotly guage chart in same row?如何在同一行中制作三个标尺图表?
【发布时间】:2021-01-02 05:30:04
【问题描述】:

我已经按照这里的参考: enter link description here

但是一旦我将“网格”从 2x2 更改为 3x3 ,它就会变得一团糟

>  fig.update_layout(
>         grid = {'rows': 3, 'columns': 3, 'pattern': "independent"},
>         template = {'data' : {'indicator': [{
>             'title': {'text': "Speed"},
>             'mode' : "number+delta+gauge",
>             }]
>                             }})

对于子图,它似乎不支持指标类型,尝试使用子图时出错

ValueError: Trace type 'indicator' is not compatible with subplot type 'xy' at grid position (1, 1) See the docstring for the specs argument to plotly.subplots.make_subplots for more information on subplot types

【问题讨论】:

    标签: plotly subplot


    【解决方案1】:

    如果我理解正确,您希望您提供的示例中的所有四个跟踪都在同一 一个行中。

    在这种情况下,您应该将 grid = {'rows': 1, 'columns': 3, 'pattern': "independent"} 传递给 fig.update_layout 方法,使用 1 行而不是 3 行。

    然后您还需要相应地更改每个跟踪的domain 参数(第 0 行、第 0 列、... 第 0 行、第 2 列),类似于循环遍历 2D 数组的方式。

    import plotly.graph_objects as go
    
    fig = go.Figure()
    
    fig.add_trace(go.Indicator(
        value = 200,
        delta = {'reference': 160},
        gauge = {
            'axis': {'visible': False}},
        domain = {'row': 0, 'column': 0}))
    
    ## domain needs to be adjusted relative to the placement of other traces
    fig.add_trace(go.Indicator(
        value = 120,
        gauge = {
            'shape': "bullet",
            'axis' : {'visible': False}},
        domain = {'x': [0, 0.38], 'y': [0.10, 0.30]}))
    
    fig.add_trace(go.Indicator(
        mode = "number+delta",
        value = 300,
        domain = {'row': 0, 'column': 1}))
    
    fig.add_trace(go.Indicator(
        mode = "delta",
        value = 40,
        domain = {'row': 0, 'column': 2}))
    
    fig.update_layout(
        grid = {'rows': 1, 'columns': 3, 'pattern': "independent"},
        template = {'data' : {'indicator': [{
            'title': {'text': "Speed"},
            'mode' : "number+delta+gauge",
            'delta' : {'reference': 90}}]
                             }})
    
    fig.show()
    

    【讨论】:

      猜你喜欢
      • 2017-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-08
      • 1970-01-01
      • 2013-05-30
      • 1970-01-01
      • 2023-01-14
      相关资源
      最近更新 更多