赞
踩
有时候,我们在 Matplotlib 中画图的时候,如果元素过多,例如图中有几十万个点,那么图片的大小会非常大。本文介绍如何减小生成的 PDF 文件大小。
使用rasterized=True
参数。
import matplotlib.pyplot as plt
import numpy as np
x = np.random.normal(0, 1, int(1e6))
y = np.random.normal(0, 1, int(1e6))
radius = np.random.normal(0, 1, int(1e6))
plt.scatter(x, y, s=radius, c=radius, cmap='Oranges', rasterized=True)
plt.show()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。