使用tex作为pdf时保存matplotlib pyplot [英] Save matplotlib pyplot while using tex as pdf

查看:52
本文介绍了使用tex作为pdf时保存matplotlib pyplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用matplotlib进行绘图.该图形已正确显示在jupyter笔记本中,但我无法将其另存为pdf.保存为 png 工作正常,但遗憾的是这不是我的选择.

I am making a plot using matplotlib. The graph is correctly displayed in jupyter notebook, but I am not able to save it as a pdf. Saving as a png works fine, but this is regrettably not an option for me.

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 custom (64-bit)|(默认值,2017年10月15日,03:27:45)[MSC v.1900 64位(AMD64)]和matplotlib版本2.1.0.

I am running python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 15 2017, 03:27:45) [MSC v.1900 64 bit (AMD64)] and matplotlib version 2.1.0.

推荐答案

也许有帮助吗?

有这个修复类型错误: https://github.com/matplotlib/matplotlib/pull/9292/commits/37ad476aec62ce58f95c91e6aabd55cfc3b5af25

There was this Fix TypeError: https://github.com/matplotlib/matplotlib/pull/9292/commits/37ad476aec62ce58f95c91e6aabd55cfc3b5af25

,这里也遇到了同样的问题: https://github.com/matplotlib/matplotlib/issues/9671

and the same problem was adressed here: https://github.com/matplotlib/matplotlib/issues/9671

要么得到固定版本,要么降级到:Matplot 2.0.2

Either you get the fixed version or downgrade to: Matplot 2.0.2

这篇关于使用tex作为pdf时保存matplotlib pyplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆