我使用scatter
函数绘制仅包含25000行的数据,但是当我使用saveas
函数将图像保存为png时,需要2分钟才能完成。
例如:
scatter(x,y,'filled');
pic_name = ['scatterplot.png'];
tic
saveas(gcf,pic_name,'png');
toc
Elapsed time is 152.681511 seconds.
是否有更快捷的方法来保存散点图?
答案 0 :(得分:1)
scatter
对大量数据点的速度很慢;可能包括保存它们(每个点都有不同的颜色,因此需要单独处理)。
您可能希望尝试以不同方式绘制数据,如下所述:matlab: scatter plots with high number of datapoints 这样,您就可以获得与常规绘图相同的行为。
答案 1 :(得分:0)
您可以尝试调用getframe()然后调用imwrite(),而不是调用saveas(),如下所示:
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');