Intermingle data points in plot

1 vue (au cours des 30 derniers jours)
Kemal
Kemal le 21 Mai 2011
Hello,
I have three data categories, which I have to plot in one figure and I want them to be intermingled, ie I don't want the category plotted last to hide the underlying data points of the other categories. In each category there are up to 40000 data points. An obvious way is to go through the data points one by one and plot point 1 of category 1, then point 1 of category 2, point 1 of category 3, point 2 of category 1, etc. - which takes hours to days.
Is there a fast way to plot data points of different categories in an intermingled fashion? Or to plot them and afterwards bring a random subset of the points to the front?
Thank you!
Kem

Réponse acceptée

Matt Fig
Matt Fig le 21 Mai 2011
It shouldn't take days to plot even that many points. Please give a small but succinct example which shows what you are doing. Something like:
cat1 = rand(3); % Three categories.
cat2 = rand(3);
cat3 = rand(3);
hold on
for ii = 1:3
plot3(cat1(ii,1),cat1(ii,2),cat1(ii,3),'*r');
plot3(cat2(ii,1),cat2(ii,2),cat2(ii,3),'*b');
plot3(cat3(ii,1),cat3(ii,2),cat3(ii,3),'*y');
end

Plus de réponses (1)

Kemal
Kemal le 21 Mai 2011
Hi Matt,
thanks for your reply.
When I wrote out the simplified version of my code, it actually plotted quickly (couple of seconds).
color{1} = [0 0 1]
color{2} = [0 1 1]
color{3} = [1 0 0];
cat{1}.x = rand(1,10000);
cat{1}.y = rand(1,10000);
cat{2}.x = rand(1,10000);
cat{2}.y = rand(1,10000);
cat{3}.x = rand(1,10000);
cat{3}.y = rand(1,10000);
figure; hold on;
for i = 1: 10000
for j = 1 : length(cat)
line(cat{j}.x(i),cat{j}.y(i),'Color',color{j},'LineStyle','.')
end
end
The problem before was that I defined which axis to plot on within the nested loop:
figure; hold on;
for i = 1: 10000
for j = 1 : length(cat)
axes(handle)
line(cat{j}.x(i),cat{j}.y(i),'Color',color{j},'LineStyle','.')
end
end
Apparently specifying the axes to plot takes a long time. I have multiple subplots in which I have to plot different forms of the data, but I now define the axes in a less nested loop and plotting is sped up tremendously that way.
figure; hold on;
axes(handle)
for i = 1: 10000
for j = 1 : length(cat)
line(cat{j}.x(i),cat{j}.y(i),'Color',color{j},'LineStyle','.')
end
end
Thank you for your help!

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by