减少散点图的文件大小 [英] Reducing file size of scatter plot

查看:63
本文介绍了减少散点图的文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试减小散点图的文件大小.我的代码看起来像:

I am currently trying to reduce the file size of a scatter plot. My code looks like:

plt.scatter(a1,b1)
plt.savefig('test.ps')

其中 a1,b1 是大小为 400,000 左右的数组,文件大小为 7.8MB.

where a1,b1 are arrays of size 400,000 or so, and it gives a file size of 7.8MB.

我试过添加

plt.rcParams['path.simplify'] = True

在此代码段之前,但文件仍为7.8MB.这是如何保存为.ps"文件的问题还是其他问题?

before this chunk of code, but the file is still 7.8MB. Is this an issue with how it saves as a ".ps" file or another issue?

推荐答案

一种方法是使用 plot 代替 scatter (您仍然可以使用'o'参数> plot ),并使用 rasterized 关键字参数,如下所示:

One approach is to use plot instead of scatter (you can still produce scatter plots using plot by using the 'o' argument), and use the rasterized keyword argument, like so:

import numpy as np 
import matplotlib.pyplot as plt

a1,b1 = np.random.randn(400000,2).T #mock data of similar size to yours
plt.plot(a1,b1,'o',rasterized=True)
plt.savefig("test.ps")

这应该会显着减小输出文件的大小.文字和艺术线条将保持为矢量,仅对点进行栅格化,因此这是一个不错的折衷方案.

This should significantly reduce the size of the output file. The text and line art will remain vector, only the points are rasterized, so it is a nice compromise.

但是,根据您希望实现的目标,最好对数据进行直方图并对其进行绘图(例如 pyplot.hist2dpyplot.hexbin).

Depending on what you're looking to achieve, however, it might be better to histogram your data and plot that instead (e.g. pyplot.hist2d or pyplot.hexbin).

这篇关于减少散点图的文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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