plotly:难以在plot注释中显示带有两个美元符号的字符串



我有一个带两个美元符号的字符串,我想在我的绘图下面用作文本注释。这段代码创建了一个字符串,您可以看到它的输出。

str = f"最大:{一},$ {numerize.numerize (b)} t" + f"最低:c {}, $ {numerize.numerize (d)}">

输出:最大值:1396,$544.41M最小值:1399,$255.31M

但是当我在下面使用str时,会巧妙地改变字体并显示意外字符:

annotations = []
annotations.append(dict(xref='paper', yref='paper', x=0.5, y=-0.15,
xanchor='center', yanchor='top',
text=str,
font=dict(family="Courier New",
size=14,
color='rgb(100,100,100)'),
showarrow=False))
fig.update_layout(annotations=annotations)

和情节中的结果:意想不到的注释

如何解决这个问题?谢谢。

  • Plotly:如何在注释中使用美元符号和换行符?需要在变成HTML
  • 的文本中使用HTML可打印字符
  • 因此解决方案变成
import plotly.graph_objects as go
from numerize import numerize
fig = go.Figure()
# # Output: Maximum: 1396 , $544.41M Minimum: 1399 , $255.31M
a = 1396
b = 544.41 * 10 ** 6
c = 1399
d = 255.31 * 10 ** 6
str = (
f"Maximum: {a} , ${numerize.numerize(b)}t"
+ f"Minimum: {c} , ${numerize.numerize(d)}"
)
ano
annotations = []
annotations.append(
dict(
xref="paper",
yref="paper",
x=0.5,
y=-0.15,
xanchor="center",
yanchor="top",
text=str,
font=dict(family="Courier New", size=14, color="rgb(100,100,100)"),
showarrow=False,
)
)
fig.update_layout(annotations=annotations)

相关内容

最新更新