栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

减小矢量轮廓图的大小

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

减小矢量轮廓图的大小

您可以使用

Axes
选项执行此操作
set_rasterization_zorder

任何

zorder
小于您设置的值的内容都将保存为栅格化的图形,即使保存为矢量格式(例如)也是如此
pdf

例如:

import matplotlib.pyplot as pltimport numpy as npdata = np.random.rand(500,500)# fig1 will save the contourf as a vectorfig1,ax1 = plt.subplots(1)ax1.contourf(data)fig1.savefig('vector.pdf')# fig2 will save the contourf as a rasterfig2,ax2 = plt.subplots(1)ax2.contourf(data,zorder=-20)ax2.set_rasterization_zorder(-10)fig2.savefig('raster.pdf')# Show the difference in file size. "os.stat().st_size" gives the file size in bytes.print os.stat('vector.pdf').st_size# 15998481print os.stat('raster.pdf').st_size# 1186334

您可以看到此matplotlib示例以获取更多背景信息。


正如@tcaswell指出的那样,要光栅化一位艺术家而不必影响它

zorder
,可以使用
.set_rasterized
。但是,这似乎不是的选项
contourf
,因此您需要遍历每个对象上和上
PathCollections
创建的对象。像这样:
contourf``set_rasterized

contours = ax.contourf(data)for pathcoll in contours.collections:    pathcoll.set_rasterized(True)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/639818.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号