python - 是否可以在 plotly 中反转子弹图?

标签 python plotly data-visualization plotly-dash plotly.graph-objects

我在 plotly.go 中创建了一个带有负维度和正维度的子弹图。但是,在绘制我的条时,它总是从 -1 开始。有没有办法将起点设置为零,以便它可以从那里在两个维度上对齐? 可重现的例子:

act = 0.123
avg = 0.13
before = 0.15
fig = go.Figure(go.Indicator(
        mode="number+gauge+delta", value=act,
        domain={'x': [0.1, 1], 'y': [0, 1]},
        title={'text': "<b>S-Score</b>"},
        delta={'reference': before},
        gauge={
            'shape': "bullet",
            'tick0':0,
            'axis': {'range': [-1, 1]},
            'threshold': {
                'line': {'color': "white", 'width': 2},
                'thickness': 0.75, 'value': avg},
            'steps': [
                {'range': [-1, 0], 'color': "#ff6666"},
                {'range': [0, 1], 'color': "#89ac76"}
            ],
            'bar': {'color': "grey"}}))

实际输出: enter image description here

我想要的输出: enter image description here

最佳答案

我已经做了很多研究,但还没有找到解决方案。我提出了一种技巧方法和更改 x 轴的建议。这与您期望的答案有点相去甚远。

import plotly.graph_objects as go

act = 0.123
avg = 0.13
before = 0.15

fig = go.Figure(go.Indicator(
    mode = "number+gauge+delta", value = act,
    domain = {'x': [0.1, 1], 'y': [0, 1]},
    title = {'text' :"<b>S-Score</b>"},
    delta = {'reference': before},
    gauge = {
        'shape': "bullet",
        'axis': {'range': [-1, 1]},
        'threshold': {
            'line': {'color': "white", 'width': 2},
            'thickness': 0.75,
            'value': avg},
        'steps': [
            {'range': [-1, 0], 'color': "#ff6666"},
            {'range': [0, 1], 'color': "#89ac76"}],
        'bar': {'color':'#ff6666'}

    }))

fig.update_layout(height = 250)
fig.show()

enter image description here

import plotly.graph_objects as go

act = 0.123
avg = 0.13
before = 0.15

fig = go.Figure(go.Indicator(
    mode = "number+gauge+delta", value = act,
    domain = {'x': [0.1, 1], 'y': [0, 1]},
    title = {'text' :"<b>S-Score</b>"},
    delta = {'reference': before},
    gauge = {
        'shape': "bullet",
        'axis': {'range': [0, 1]},
        'threshold': {
            'line': {'color': "white", 'width': 2},
            'thickness': 0.75,
            'value': avg},
        'steps': [
            {'range': [-1, 0], 'color': "#ff6666"},
            {'range': [0, 1], 'color': "#89ac76"}],
        'bar': {'color':'grey',
                'line': {'color':'#444', 'width':2},
    }}))

fig.update_layout(height = 250)
fig.show()

enter image description here

关于python - 是否可以在 plotly 中反转子弹图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63642066/

相关文章:

R:ggplot2 图例未显示

python - 创建散点图矩阵时如何更改seaborn中的颜色优先级

python - 如何在 Altair 中调整比例范围?

python - 使用更重要的最近观察值计算平均值

python - 属性错误 : 'SigSafeLogger' object has no attribute 'logger'

python - 如何删除一列中括号内的数据?

python - 如何使用带有 Pandas 数据帧的请求来创建多个 Get http 请求?

javascript - PlotlyJS - 设置曲面图中类别轴的长度

python - 带有 plotly 的基本条形图

javascript - 导入第三方库es6