plotly / Kaleido

Fast static image export for web-based visualization libraries with zero dependencies
MIT License
378 stars 38 forks source link

Exporting png with a $ in a text label #54

Closed jtamerius closed 4 years ago

jtamerius commented 4 years ago

Hey All,

I am using Plotly and Kaleido to export a png. The legend text labels begin with dollar signs such as '$50k' but this is special character (or something) and causes the text to become smaller font, truncated and italicized. If I use an escape character such as '\$50k' the text label stays '\$50k'. If I do r'$50k' it works when I output to html but not png (converts to smaller font, etc). Any help on getting around this would be much appreciated!

Thanks, James

jonmmease commented 4 years ago

Hi @jtamerius,

It sounds like Latex rendering mode is somehow being triggered. But this should only happen if the first and last characters are $.

import plotly.io as pio
import plotly.graph_objects as go
pio.templates.default = None

pio.show(
    go.Figure(data=go.Scatter(y=[1, 3, 2], name="$Hello", showlegend=True)),
    renderer="png", engine="kaleido"
)

single_dollar

pio.show(
    go.Figure(data=go.Scatter(y=[1, 3, 2], name="$Hello$", showlegend=True)),
    renderer="png", engine="kaleido"
)

double_dollar

If you only have a leading $, and you're seeing an issue, could you provide an example that reproduces it?

Regardless, a workaround is to use the HTML code for the dollar symbol (see http://cactus.io/resources/toolbox/html-currency-symbol-codes)

pio.show(
    go.Figure(data=go.Scatter(y=[1, 3, 2], name="$Hello$", showlegend=True)),
    renderer="png", engine="kaleido"
)

double_dollar_escaped

jtamerius commented 4 years ago

You caught me. I didn't provide the entire label in my post because I didn't think it mattered. My bad. The entire label is '$50k-$100k'. The solution you have provided works -- thanks!