Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

Plot annotation: Difficulty in displaying a string with two dollar signs

Hello, everybody!
I have a string with two dollar sign, and I want to be used as a text annotation below my plot.
This code created a string and you can see its output.

str=f"Maximum: {a} , ${numerize.numerize(b)}\t"+f"Minimum: {c} , ${numerize.numerize(d)}" 
print(str)
Output: Maximum: 1396 , $544.41M	Minimum: 1399 , $255.31M

but when I use str in below, plotly changes font and shows unexpected characters:

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)

and the result in plot:

Capture

How can I fix this issue? Thanx.

1 Like

Solution:

Need to use HTML printable characters in text that becomes HTML.

like this:

str = (
    f"Maximum: {a} , ${numerize.numerize(b)}\t"
    + f"Minimum: {c} , ${numerize.numerize(d)}"

I think this is caused by the Latex typesetting feature that is done when you have any string between two dollar signs ($) e.g. $this latex$. Not sure this would work but you can also try escaping the dollar sign with a backslash before the sign e.g. \$this latex\$.

1 Like

Thanks pokgak.
before this, I didn’t know latex could be used with plotly,

but the solution:

‘need to use HTML printable characters in text that becomes HTML’ as Rob Raymond said here.

Html representation of dollar sign:     $