pythonplotlyjupyterkaleido

Plotly Python: Export image with different font styles


Problem Summary

I'm trying to export a plotly figure with multiple fonts / font stylings as a .png file. Within the browser, the figure renders correctly. The y-axis has different font style that the rest of the figure. Both fonts are installed on my system. enter image description here

But if I try to export the image as a png-file, the different font styling for the y-axis seems to disappear.

enter image description here

Minimum code example

`

import pandas as pd
import plotly.express as px

df = pd.read_csv("https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv")

fig = px.histogram(df, x="Age", color="Sex")

fig.update_layout(font_family="Arial")
fig.update_yaxes(tickfont_family="Arial Black")
fig.show()

fig.write_image("test_image.png")

`

My issue might be related to this post. But both fonts are installed on my machine.

Does anyone know how to include multiple fonts in a plotly figure export?


Solution

  • It seems that the issue has to do with kaleido:0.2.1 when installed via conda.

    If kaleido:0.2.1 is installed via pip, the export of images with different font styles works just fine.