我有一个代表 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
您可以使用
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"))
您可以在
annotation_font_color='red'
内添加fig.add_hrect()
。
所以将会是:
fig.add_hrect(
y0=1,
y1=1,
annotation_text='KPI not satisfied',
annotation_font_color='red',
...
)