Plotly Gauge - 可以关闭中心值吗?

Plotly Gauge - Possible to turn off Value in center?

我有一个使用以下代码生成的仪表图。是否可以隐藏显示的值 74,但仍将其用作仪表条的驱动程序?我想实际使用一个文本字符串来“分类”,比如等级。因此 74 将是 C,我实际上想显示一个 C。有什么建议吗?

score = 74
if round_score in range(0, 60):
    bar_color = '#972735'
elif round_score in range(59, 71):
    bar_color = '#E46138'
elif round_score in range(70, 81):
    bar_color = '#232B37'
elif round_score in range(80, 91):
    bar_color = '#00498D'
elif round_score in range(90, 101):
    bar_color = '#036048'
else:
    bar_color = '#596987'   

fig = go.Figure(go.Indicator(
    mode = "gauge+number",
    value = round_score,
    domain = {'x': [0, 1], 'y': [0, 1]},
    title = {'text': "<b>Score</b>"},
    gauge = {
            'axis': {'range': [0,100]},
                     #{'visible':False},
             'bar':{'color': bar_color},
             'bgcolor': 'white'
            }))

Gauge Plot

要隐藏绘图中的“74”,只需将模式从“gauge+number”更改为“gauge”即可。

要绘制“C”,您可以使用 fig.add_annotation()

您的代码可能如下所示:

import plotly.graph_objects as go

round_score = 74
if round_score in range(0, 60):
    bar_color = '#972735'
    score = 'E'
elif round_score in range(59, 71):
    bar_color = '#E46138'
    score = 'D'
elif round_score in range(70, 81):
    bar_color = '#232B37'
    score = 'C'
elif round_score in range(80, 91):
    bar_color = '#00498D'
    score = 'B'
elif round_score in range(90, 101):
    bar_color = '#036048'
    score = 'A'
else:
    bar_color = '#596987'
    score = 'F'

fig = go.Figure()

fig.add_trace(go.Indicator(
    mode = "gauge",
    value = round_score,
    domain = {'x': [0, 1], 'y': [0, 1]},
    title = {'text': "<b>Score</b>"},
    gauge = {'axis': {'range': [0,100]},
             'bar':{'color': bar_color},
             'bgcolor': 'white'
            }
    )
)

fig.add_annotation(x=0.5, y=0.3,
            text=score,
            font={'size': 50},
            showarrow=False)

fig.show()