如何在同一行制作三个 plotly gauge 图表?
How can I make three plotly guage chart in same row?
我已经按照这里的参考:
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
如果我没理解错的话,您希望您提供的示例中的所有四个轨迹都在同一 一个 行中。
在这种情况下,您应该将 grid = {'rows': 1, 'columns': 3, 'pattern': "independent"}
传递给 fig.update_layout
方法,其中包含 1 行而不是 3 行。
然后您还需要相应地更改每个跟踪的 domain
参数(第 0 行,第 0 列,...第 0 行,第 2 列),类似于循环遍历二维数组的方式。
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()
我已经按照这里的参考: 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
如果我没理解错的话,您希望您提供的示例中的所有四个轨迹都在同一 一个 行中。
在这种情况下,您应该将 grid = {'rows': 1, 'columns': 3, 'pattern': "independent"}
传递给 fig.update_layout
方法,其中包含 1 行而不是 3 行。
然后您还需要相应地更改每个跟踪的 domain
参数(第 0 行,第 0 列,...第 0 行,第 2 列),类似于循环遍历二维数组的方式。
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()