当我运行 Matplotlib's multi page example 的修改版本时在标题中添加了一个选项卡后,我得到以下输出:
这是我的工作示例。代码上面的注释是我找到的建议here在Non-ASCII characters in Matplotlib , 但到目前为止没有成功。
# -*- coding: utf-8 -*-
import matplotlib
from matplotlib.backends.backend_pdf import PdfPages
from pylab import *
#matplotlib.rc('font', family='DejaVu Sans')
#matplotlib.rc('font', **{'sans-serif' : 'Arial',
# 'family' : 'sans-serif'})
#matplotlib.rcParams['pdf.fonttype'] = 42
#matplotlib.rcParams['ps.fonttype'] = 42
pdf = PdfPages('multipage_pdf.pdf')
figure(figsize=(3,3))
plot(range(7), [3,1,4,1,5,9,2], 'r-o')
title('Page\tOne')
savefig(pdf, format='pdf') # note the format='pdf' argument!
close()
pdf.close()
有什么解决办法吗?
最佳答案
解决方法是添加
matplotlib.rcParams['ps.useafm'] = True
matplotlib.rcParams['pdf.use14corefonts'] = True
matplotlib.rcParams['text.usetex'] = True
我找不到哪一行有魔力,在我的情况下似乎不需要所有的,但我只是添加了所有。如果 tex 提示无法对某些内容进行编码有问题,您可以评论 ['text.usetex']
它仍然有效。
来自 matplotlib 文档:
Add "pdf.use14corefonts: True" in your configuration file to use only the 14 PDF core fonts. These fonts do not need to be embedded; every PDF viewing application is required to have them. This results in very light PDF files you can use directly in LaTeX or ConTeXt documents generated with pdfTeX, without any conversion.
These fonts are: Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique, Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique, Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, Symbol, ZapfDingbats.
关于python - 为什么 Matplotlib 的 PdfPages 将选项卡打印为框(字体编码)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47346635/