将仪表指示器中的条形原点设置为从 plot.ly 中的 0 开始

Set the bar origin in gauge indicator to start at 0 in plot.ly

我想让深蓝色条从 0 开始,以便能够将它用于负值和正值。

目前我不知道如何定义它,根据参考文献判断。 https://plotly.com/python/reference/indicator/ https://plotly.com/python/bullet-charts/

import plotly.graph_objects as go
fig = go.Figure(go.Indicator(
    mode = "number+gauge+delta", value = 10,
    domain = {'x': [0, 1], 'y': [0, 1]},
    delta = {'reference': 10, 'position': "top"},
    title = {'text':"<b>Gearing</b><br><span style='color: gray; font-size:0.8em'>Finanical<br>Stability</span>", 'font': {"size": 14}},
    gauge = {
        'shape': "angular",
        'axis': {'range': [-100, 100]},
        'threshold': {
            'line': {'color': "red", 'width': 2},
            'thickness': 0.75, 'value': 70},
        'bgcolor': "white",
        'steps': [
            {'range': [-100, 100], 'color': "cyan"},
            {'range': [-50, 50], 'color': "royalblue"}],
        'bar': {'color': "darkblue"}}))
fig.update_layout(height = 250)
fig.show()

显示值=10

这显示值=0

这是显示值=-40

我找到了一种仅使用 steps 即可模拟您想要实现的外观的方法。我所做的是隐藏 bar 设置 bar.thickness = 0 然后添加额外的 stepstep.range = [0, value]thickness <= 1.

我正在使用 Plotly.js,但代码应该类似。

const data = {
  value: x
  type: 'indicator',
  mode: 'number+gauge',
  gauge: {
    shape: 'angular',
    bar: { thickness: 0 },
    steps: [
          {
            range: [-3500, 3500],
            color: 'cyan',
            thickness: 1,
          },
          {
            range: [-1200, 1200],
            color: 'royalblue',
            thickness: 1,
          },
          {
            range: [0, x],
            color: 'blue',
            thickness: 0.8,
          },
        ]
  },
}

Negative value Positive value