Matplotlib PDF 后端慢? [英] Matplotlib PDF backend slow?

查看:60
本文介绍了Matplotlib PDF 后端慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 matplotlib 将一千个图写入 PDF.我已经优化了绘图代码,即.重复使用图形/轴/线并更改 y 数据.

I'm writing a thousand plots to a PDF using matplotlib. I've already optimized the plotting code, ie. reusing figures/axes/lines and just changing the y data.

剩下的大部分时间都花在了 save_figure 上.

The bulk of the remaining time is spent in save_figure.

相比之下,R 似乎将绘图输出到 PDF 的速度提高了大约 2 倍.在 R 中绘制全零数据似乎更快,而在 Python 中它们的速度相同.

R, in comparison, seems to output a plot to PDF about 2x faster. Plots will all zero data seem to be even faster in R, while they're the same speed in Python.

我已经设置了 pdf.compression = 0,这是一个小小的改进.

I've set pdf.compression = 0, which makes a small improvement.

尝试光栅化数据,它对绘图速度没有影响(尽管它使用了大量 RAM).

Tried rasterizing the data, it made no difference to plotting speed (although it used a ton of RAM).

还有什么我可以尝试用 PDF 后端加速 matplotlib 的吗,或者我应该考虑任何其他后端?我正在努力打败 R.

Is there anything else I can try to speed up the matplotlib with PDF backend, or are there any alternative backends I should consider? I'm trying to beat R.

谢谢!

推荐答案

不得不试pyreport 来自 Gael Varoquaux?您在脚本中调用它,然后它收集对 pylab.show() 的所有调用,为每个调用生成一个 png,然后从中创建一个 PDF.

Have to tried pyreport from Gael Varoquaux? You call it on your script, it then collects all calls to pylab.show(), makes a png of each and then creates a PDF from it.

它最终使用 Latex ,所以你需要这个.但我希望这可能会更快,因为 PDF 创建委托给 Latex.

It uses Latex in the end, so you'll need this. But I expect this might be faster, as PDF creation is delegated to Latex.

这篇关于Matplotlib PDF 后端慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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