Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

matlab: scatter plots with high number of datapoints

I'm trying to plot scatter, something like:

scatter(coor(:, 2), coor(:, 3), 1, coor(:, 4));

The problem is, that I have quite big number of coordinates to plot (~100 000). Its taking long time to plot it, and when I try to export figure to tiff - then matlab is dead for goooood few minutes... Any solution to improve plotting, or at least tiff export?

EDIT: Forgot to mention, 3rd coordinate (coor(:, 4)) is a color code.

So, when I'm using scatter (as above), I have something like on the image below, and thats exactly how I want to see it (just its super slow and I can't export that):

scatter

When I do:

plot3(coor(:, 2), coor(:, 3), coor(:, 4), '.')

effect is not as cool any more (note: images are not from the same coordinates...) :

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use plot, but then all points have the same color. However, you can divide the set in different subsets and plot them each with their own color:

N = 100000;
x = rand(N,1);
y = rand(N,1);
C = sin(2*x)+y;

cdivs = 10;
[~, edges] = hist(C,cdivs-1);
edges = [-Inf edges Inf]; % to include all points
[Nk, bink] = histc(C,edges);

figure;
hold on;
cmap = jet(cdivs);
for ii=1:cdivs
    idx = bink==ii;
    plot(x(idx),y(idx),'.','MarkerSize',4,'Color',cmap(ii,:));
end

colormap(cmap)
caxis([min(C) max(C)])
colorbar

enter image description here

which responds already a lot better than scatter(x,y,1,C) which gives about the same plot, but with higher color resolution (which is adjustable in my code above).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...