Question

I have 3 arrays x,y,c where each value of c is an intensity for x,y ranging between approximately -3 and 3

I want to plot each point as a filled circle with a color determined by the intensity c.

I have tried using scatter(x,y,10,c) but this basically crashes my computer because there is so much data.

Note each array contains approximately 500,000 data points.

Is there a better way I can plot this?

Était-ce utile?

La solution

I think your datasets are too large to plot with the method that you're describing. If you have 500k datapoints, and each "filled circle" takes up 5 pixels, your data wouldn't be able to fit in a usual 1000x1000 full-screen plot.

Two ideas for you:

(1) If this is the behavior you want, you have to accept that you're not going to see all the data because some of the points will obstruct the others by being on top of them. Subsample the dataset using something like

temp = randperm(500000); temp = temp(1:10000); scatter(x(temp),y(temp),10,c(temp));

Yes, you'll lose some data this way, but you were going to lose it from obstruction anyway. This is the easiest method for quick visual checks.

(2) If you do want to see all your data, then you should look into writing a custom plotting routine for your needs. Here's the basic gist of it:

myImage = zeros(1000, 1000);
X_MIN = min(x);
Y_MIN = min(y);
X_RANGE = max(x) - min(x);
Y_RANGE = max(y) - min(y);
for idx = 1:500000
  xIndex = round( (x(idx) - X_MIN) * 999/(X_RANGE)) + 1;
  yIndex = round( (x(idx) - Y_MIN) * 999/(Y_RANGE)) + 1;
  myImage(xIndex, yIndex) = myImage(xIndex, yIndex) + c(idx);
end
imshow(myImage, []);

I haven't checked this so there might be an indexing bug, but you get the drift. You'll probably want to vectorize this code using sub2ind if you'll be calling it a lot.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top