1

I have a gauge plot that I have produced using the following code. Is it possible to hide the value 74 shown, but still use it as the driver of the bar on the gauge? I want to actually use a text string to "categorize", like a grade. Thus 74 would be a C and I would actually want to show a C. Any suggestions?

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

KMarieZ84
  • 25
  • 4

1 Answers1

1

To hide the "74" in your plot, simply change the mode from "gauge+number" to "gauge".

To plot instead a "C", you can use fig.add_annotation().

Your code could then look like:

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()
Pascalco
  • 2,481
  • 2
  • 15
  • 31