Python Plotly SVG 图形奇怪的字体问题

Python Plotly SVG Graphics Weird Font Issue

我正在尝试使用 Plotly 创建旭日图。一切正常,除了将新创建的 SVG 文件导出到 Overleaf 并使用 LaTeX 代码创建 PDF 之后,图像看起来很奇怪。文字脱离图像并相互重叠。 Check the demo image here.

这是我用来生成图像的代码。

import pandas as pd
import plotly.express as px
import os

df = pd.read_excel('data/countries.xlsx')
df.head()

fig = px.sunburst(df, path=['Continent', 'Country'])
fig.show()

graphics_dir = "graphics"
if not os.path.exists(graphics_dir):
    os.mkdir(graphics_dir)

fig.write_image(format='svg', file='{}/countries.svg'.format(graphics_dir))

我知道在使用 中的 Matplotlib 生成图形时如何解决这个问题,它对我有用。但我不知道如何在 Plotly 中实现这一点。

根据我一位同事的建议,我成功破解了整个过程。由于我无法禁用 SVG 的字体路径,因此我选择了另一种方法。 首先,我将 SVG 文件转换为 PDF,然后我使用 PDF 而不是那个 SVG 文件。将 SVG 转换为 PDF 的好处是 SVG 的字体路径在 PDF 中不再可用。它们嵌入到 PDF 中。 这样,我设法解决了这个问题!谢谢。