注释的绘图颜色

问题描述 投票:0回答:2

我有一个代表 KPI 的散点图。在 KPI 值下方有一个绿色矩形,在红色矩形上方有一个都是使用“fig.add_hrect()”创建的。我使用以下方式添加文本来指示“KPI 不满意”:

        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)

文本是黑色的,我找不到将注释文本变成红色的方法。

任何帮助表示赞赏, Tx/ALain

text colors annotations
2个回答
3
投票

您可以使用

fig.update_annotations()
更改注释文本。以下是相同的示例...

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"))


0
投票

您可以在

annotation_font_color='red'
内添加
fig.add_hrect()
。 所以将会是:

fig.add_hrect(
    y0=1,
    y1=1, 
    annotation_text='KPI not satisfied',
    annotation_font_color='red',
    ...
)
© www.soinside.com 2019 - 2024. All rights reserved.