我正在使用 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],
[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'
完整的错误转储:https://pastebin.com/rFTr3ehU
我正在运行 python 3.6.3 |Anaconda 自定义(64 位)| (默认,2017 年 10 月 15 日,03:27:45)[MSC v.1900 64 位 (AMD64)] 和 matplotlib 版本 2.1.0。