我使用scatter
函数来绘制仅包含25000行的数据,但是当我使用saveas
函数将图像保存为png时,需要2分钟才能完成此操作。MATLAB:保存散点图花费时间过长
例如:
scatter(x,y,'filled');
pic_name = ['scatterplot.png'];
tic
saveas(gcf,pic_name,'png');
toc
Elapsed time is 152.681511 seconds.
有没有更快的方式保存散点图?
我使用scatter
函数来绘制仅包含25000行的数据,但是当我使用saveas
函数将图像保存为png时,需要2分钟才能完成此操作。MATLAB:保存散点图花费时间过长
例如:
scatter(x,y,'filled');
pic_name = ['scatterplot.png'];
tic
saveas(gcf,pic_name,'png');
toc
Elapsed time is 152.681511 seconds.
有没有更快的方式保存散点图?
而不是调用另存为(),你可以尝试调用getFrame()方法,然后调用imwrite(),像这样的:
npoints = 25000;
x = linspace(0,3*pi, npoints);
y = cos(x) + rand(1, npoints);
scatter_series_handle = scatter(x,y,'filled');
pic_name = ['scatterplot.png'];
axes_handle = get(scatter_series_handle, 'Parent');
figure_handle = get(axes_handle, 'Parent');
img = getframe(figure_handle);
imwrite(img.cdata, pic_name, 'png');
scatter
被称为是高数目的数据点慢;这可能包括保存它们(每个点有不同的颜色,因此需要单独处理)。
您可能想尝试以不同方式绘制数据,如下所述:matlab: scatter plots with high number of datapoints 这样,您将获得与常规绘图相同的行为。
需要在我的电脑3秒。我有一个很好的,但仍然差异很大。另外25000个值不是“唯一的”,它是一个相当高的值。 –
确实如此,但我仍然可以很快地保存有500k行数据的常规地块。 – Bensa
@BehnazEnsan你用过'export_fig'吗? http://www.mathworks.com/matlabcentral/fileexchange/23629-export-fig – rayryeng