How to add text on each colored range

Viewed 83

I am plotting a gauge plot

import plotly.graph_objects as go

fig = go.Figure(go.Indicator(
    mode = "gauge",
    domain = {'x': [0, 1], 'y': [0, 1]},
    title = {'text': "water level", 'font': {'size': 16}},
    gauge = {
        'axis': {'range': [None, 370], 'tickwidth': 2, 'tickcolor': "black", 'tickvals':[90,260,370],},
        'bar': {'color': "lightgrey"},
        'bgcolor': "white",
        'borderwidth': 1.5,
        'bordercolor': "white",
        'steps': [
            {'range': [0, 90], 'color': "green"},
            {'range': [90, 260], 'color': 'yellow'},
            {'range': [260, 370], 'color': "red"}, ],}))

fig.update_layout(paper_bgcolor = "white", font = {'color': "black", 'family': "Arial"})
fig.show()

and the plot looks like this: enter image description here

How can I move the title up and add text 'safe', 'average', and 'dangerous' on each colored range?

1 Answers

The position of the text is set manually, but it is possible to use annotations. The title can be moved by adjusting the domain, but the graph size will be reduced, so you will have to find another way.

fig.add_annotation(x=0.35, y=0.35, text='safe', showarrow=False)
fig.add_annotation(x=0.5, y=0.9, text='average', showarrow=False)
fig.add_annotation(x=0.7, y=0.35, text='dangerous', showarrow=False)

enter image description here

Related