为什么尽管栅格化为True,但matplotlib图形文件仍会很大? [英] Why is matplotlib figure filesize huge despite rasterized=True?

查看:37
本文介绍了为什么尽管栅格化为True,但matplotlib图形文件仍会很大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的例子:

from matplotlib.pyplot import plot, savefig
from numpy.random import randn

plot(randn(100),randn(100,500),"k",alpha=0.03,rasterized=True)
savefig("test.pdf",dpi=90)

产生:

但是文件大小大约是 8Mb.任何想法出什么事了吗?这可能是错误吗?我使用的是Python 3.5.1和Matplotlib 2.1.2.

But the file size comes out to be ~8Mb. Any ideas what's going wrong? Could this be a bug? I'm on Python 3.5.1 and Matplotlib 2.1.2.

推荐答案

完整的答案似乎在此处的注释中: https://stackoverflow.com/a/12102852/1078529

Looks like the full answer is in the comment to here: https://stackoverflow.com/a/12102852/1078529

技巧是使用 set_rasterization_zorder 将某个zorder下方的所有内容一起光栅化为单个位图,

The trick is to use set_rasterization_zorder to rasterize everything below a certain zorder together into a single bitmap,

gca().set_rasterization_zorder(1)
plot(randn(100),randn(100,500),"k",alpha=0.03,zorder=0)
savefig("test.pdf",dpi=90)

这篇关于为什么尽管栅格化为True,但matplotlib图形文件仍会很大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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