【问题标题】:plotly : Difficulty in displaying a string with two dollar signs in plot annotation [duplicate]plotly:难以在绘图注释中显示带有两个美元符号的字符串[重复]
【发布时间】:2021-11-07 12:34:40
【问题描述】:

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

str=f"最大值:{a},${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)

以及图中的结果: unexpected annotation

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

【问题讨论】:

    标签: python string annotations plotly dollar-sign


    【解决方案1】:
    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)
    
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-10
      • 2015-08-21
      • 1970-01-01
      • 1970-01-01
      • 2022-07-05
      相关资源
      最近更新 更多