我正在尝试创建我在 jupyter 实验室中用绘图绘制的 PDF,但我在字体方面遇到了很多麻烦。Plotly 对浏览器中的所有普通文本使用正确的字体,但所有 LaTeX 代码标签都使用不同的字体。这是可以预料的,因为plotly 使用 MathJax 进行渲染,并且显然它被配置为使用STIX. 我可以接受这一点,并将非 LaTeX 字体更改为STIX与导出的图形一致。真正困扰我的是,当我将绘图导出为 PDF 时,LaTeX 标签使用另一种字体。由于某种原因,MathJax 默认为MathJax_Main. 如果导出为 PNG 或 PDF,则为了完全混淆,默认使用普通字体Liberation Serif。
因此,这里有一些用于创建绘图的示例代码。我在 Debian 11 和 python 3.9 上运行它。requirements.txt如果有用的话我可以添加完整的。
import plotly.graph_objects as go
from plotly.express.colors import qualitative
layout = go.Layout(
font=dict(
family='Latin Modern Math',
color='black',
size=20,
),
colorway=qualitative.D3,
width=600,
height=320,
margin=dict(l=10,r=10,t=10,b=10),
paper_bgcolor='rgba(255,255,255,1)',
plot_bgcolor='rgba(0,0,0,0)',
xaxis=dict(
showline=True,
linecolor='black',
ticks='inside',
exponentformat='e',
mirror='ticks',
),
yaxis=dict(
showline=True,
linecolor='black',
ticks='inside',
exponentformat='e',
mirror='ticks',
),
legend=dict(
xanchor="left",
yanchor="bottom", …Run Code Online (Sandbox Code Playgroud)