matlab: scatter plots with high number of datapoints

后端 未结 4 1292
栀梦
栀梦 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:35

    My experience is that the most efficient plotting command in matlab is Patch, and I have used it to emulate the functionality of scatter or scatter3 with much higher efficiency.

    If you have a list of points, use each point to define a square patch (or octagons, or whatever) of reasonable edge length for your particular data, then plot the collection of patches with a single call to patch. After the graphic object is created, you can update its color data to individually color the squares.

    You can use the same concept in 3D by building cubes or 3D crosses from your data set.

    This snippet creates 1e5 randomly placed squares, with random colors in this case and runs in a little under a second on my four year old laptop. A similar call to scatter takes 40 seconds, and returns an unwieldy figure that is hard to manipulate.

    tic
    P=rand(1e5,2);
    Edge=.01;
    X=[P(:,1)'; P(:,1)'+Edge; P(:,1)'+Edge; P(:,1)'];
    Y=[P(:,2)'; P(:,2)'; P(:,2)'+Edge; P(:,2)'+Edge];
    figure;
    h=patch(X,Y,'r');
    set(h,'facevertexcdata',rand(size(X,2),3),'facecolor','flat','edgecolor','none')
    drawnow
    toc
    

提交回复
热议问题