plotly pdf export changes font style

Viewed 193

I want to save a figure that I created with plotly. In jupyter notebook, my plot has the right font. But when I save my figure to a pdf file, it changes the font. How can I keep the font?

import plotly.graph_objects as go
import plotly.io as pio

fig = go.Figure()
fig.update_layout(title="As you can see the font changes, how can I keep the font?",
                 font_family = "Latin Modern Roman")

fig.show()
pio.write_image(fig, "test.pdf")

Figure in jupyter notebook:

enter image description here

But the saved figure looks like this:

enter image description here

1 Answers

Unfortunately, it looks like there may not be an easy solution, as this issue is being tracked as a bug on the plotly GitHub.

But until the issue gets resolved, it seems that in order for the png exports to work properly, one should use fonts installed on the system (which may not be the same as those recognized by the browser/jupyter notebook, hence the discrepancy).

On Mac OS, what worked for me was looking at what fonts were available in the Font Book and using those in the images to be exported to png.

Related