简体   繁体   中英

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. 在此处输入图像描述

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

在此处输入图像描述

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM