matlab: scatter plots with high number of datapoints

后端 未结 4 1285
栀梦
栀梦 2020-12-03 10:59

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 o

4条回答
  •  一生所求
    2020-12-03 11:28

    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).

提交回复
热议问题