plotly color of annotation

Viewed 13

I have a scatter plot which represents a KPI. Below the KPI value I have a green rectangle, above a red rectangle created both with "fig.add_hrect()". I add text to indicate "KPI not satisfied" using:

        fig.add_hrect(y0=sbf._KPI_CODERES_THRESHOLD, y1=residual_max,
                      annotation_text='KPI not satisfied', annotation_position='top',
                      fillcolor='red', opacity=0.05, line_width=0)

The text is in black and I cannot find a way to have the annotation text colored red.

Any help appreciated, Tx/ALain

1 Answers

You can use fig.update_annotations() to change the annotation text. Below is a sample of the same...

import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="petal_length", y="petal_width") ## My dummy plot
fig.add_hrect(y0=1, y1=1, annotation_text='KPI not satisfied', annotation_position='top', 
              fillcolor='red', opacity=0.05, line_width=0)

fig.update_annotations(font=dict(family="sans serif", size=18, color="red"))

enter image description here

Related