如何在matplotlib生成的pdf中嵌入字体?

2024-05-16 02:13:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是一种名为ttf的字体,名为FreeSans on linux和matplotlib。我将我的图形创建为:

from matplotlib import rc
plt.rcParams['ps.useafm'] = True
rc('font',**{'family':'sans-serif','sans-serif':['FreeSans']})
plt.rcParams['pdf.fonttype'] = 42
plt.figure()
# plot figure...
plt.savefig("myfig.pdf")

当我在另一个程序(如MacOSX上的illustrator)上打开它时,字体不会出现,而是使用默认字体,因为FreeSans不可用。

我怎样才能使matplotlib将字体嵌入到它生成的每个PDF文件中?我不介意文件大点。谢谢。


Tags: 文件图形pdfmatplotlibonlinux字体plt
2条回答

你确定它已经不做了吗?从网站:

matplotlib has excellent text support, including mathematical expressions, truetype support for raster and vector outputs, newline separated text with arbitrary rotations, and unicode support. Because we embed the fonts directly in the output documents, eg for postscript or PDF, what you see on the screen is what you get in the hardcopy.

以前,我经常输出一个.ps文档,并使用ps2pdf-dEmbedAllFonts=true选项。

我在用matplotlib生成pdf时也遇到同样的问题。

有趣的是,如果我在pdf中指定使用TrueType,字体将被嵌入:

matplotlib.rc('pdf', fonttype=42)

相关问题 更多 >