Python 3.x 将tex用作pdf时保存matplotlib pyplot
我正在使用matplotlib绘制一个绘图。该图正确显示在jupyter笔记本中,但我无法将其保存为pdf格式。保存为png很好,但遗憾的是,这不是我的选择Python 3.x 将tex用作pdf时保存matplotlib pyplot,python-3.x,matplotlib,Python 3.x,Matplotlib,我正在使用matplotlib绘制一个绘图。该图正确显示在jupyter笔记本中,但我无法将其保存为pdf格式。保存为png很好,但遗憾的是,这不是我的选择 import numpy as np import matplotlib.pyplot as plt from matplotlib.backends.backend_pdf import PdfPages values= [[0, -1.055], [2.5, -1.798], [6.5, -1.662], [9, -1.274
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
values= [[0, -1.055], [2.5, -1.798], [6.5, -1.662], [9, -1.274],
[10, -0.939], [11, -0.527], [12, -0.338], [15, 0.345],
[17, -0.146], [19, -1.526], [19, -1.395], [21, -2.454]]
values= np.array(values)
fig = plt.figure(1, figsize=(9,6.5))
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.scatter(values[:,0], values[:,1])
plt.show()
pdf = PdfPages('test.pdf')
pdf.savefig(fig)
pdf.close()
我得到以下错误:
TypeError: a bytes-like object is required, not 'str'
完全错误转储:
我正在运行python 3.6.3 | Anaconda custom(64位)|(默认,2017年10月15日,03:27:45)[MSC v.1900 64位(AMD64)]和matplotlib版本2.1.0。这可能有帮助吗
出现以下修复类型错误:
这里也提到了同样的问题:
您获得了固定版本或降级到:Matplot 2.0.2您是否尝试只使用
fig.savefig('test.pdf')
而不是使用PdfPages
?使用python 2.7(64位)和matplotlib 2.1.2,代码在jupyter笔记本中运行良好。水蟒的分布会有问题吗?