How can I create a vector of markers for a scatter plot

8 Ansichten (letzte 30 Tage)
Kundera
Kundera am 17 Jun. 2018
Bearbeitet: dpb am 17 Jun. 2018
Hey, I am trying to plot the following:
y = randi(10, 12, 3);
x = randi(10, 12, 3);
figure
scatter (x(:,1), y(:,1), 'MarkerFaceColor', [102, 215, 209]./255)
hold on
scatter (x(:,2), y(:,2), 'MarkerFaceColor', [253,174,97]./255)
scatter (x(:,3), y(:,3), 'MarkerFaceColor', [215,25,28]./255)
The 3 colours representing 3 subgroups of my data, but I'd also like to have the same Marker for each row entry. So that I have for example one Marker
[x(1,1), y(1,1)], [x(1,2), y(1,2)] and [x(1,3), y(1,3)],
another Marker for
[x(2,1), y(2,1)], [x(2,2), y(2,2)] and [x(2,3), y(2,3)]
and so on.
How can I do it? Thanks
  2 Kommentare
Kundera
Kundera am 17 Jun. 2018
Maybe I should move to a traditional plot then? But how should I define the 12 markers?
y = randi(10, 12, 3);
x = randi(10, 12, 3);
figure
plot (x(:,1), y(:,1), 'MarkerFaceColor', [102, 215, 209]./255)
hold on
plot (x(:,2), y(:,2), 'MarkerFaceColor', [253,174,97]./255)
plot (x(:,3), y(:,3), 'MarkerFaceColor', [215,25,28]./255)
dpb
dpb am 17 Jun. 2018
Gots same problem either way, a linestyle is only a single value for each line so the color and marker are the same for every point along the line. See updated Answer.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

dpb
dpb am 17 Jun. 2018
Bearbeitet: dpb am 17 Jun. 2018
...
c=[102, 215, 209;253,174,97;215,25,28]/255;
m=['o','d','s'];
figure, hold on
for i=1:size(x,2)
scatter (x(:,i), y(:,i), 'MarkerFaceColor', c(i,:),'Marker',m(i))
end
First thought you wanted one by column and the other by row; that's not doable except by every point an object...this is ok as each row is a single object.
ADDENDUM
OK, so my first thought was right; the above is right answer to wrong Q??? :)
You're fortunate there are more than twelve possible markers already defined; you do just like for the colors, define(*) an array of their names and use it...
m={'+', 'o', '*', '.', 'x', 'square', 'diamond', 'v', '^', '>', '<', 'pentagram'};
[nr,nc]=size(x);
for i=1:nr
for j=1:nc
scatter(x(i,j),y(i,j),'MarkerFaceColor',c(j,:),'Marker',m{i})
end
end
(*) I created the list by causing scatter to error on a bad call at which it echos the allowable list of names a la the list in the doc. There has to be a way to use the default marker order vector and factory defaults for the markers to automate this but I've never been able to get through the maze to figure out how to get to the information in useful manner...for all the doc there is, much of HG2 is highly opaque and almost impenetrable to the casual user who doesn't have time nor inclination to learn the details of the object hierarchy. It's like being a casual Excel user and try to write a "quick" macro--just ain't a-gonna' happen. :(

Weitere Antworten (1)

Ameer Hamza
Ameer Hamza am 17 Jun. 2018
So you mean you want to have a total of 12 different markers? You can specify the marker shape Using the third argument of scatter(). For Example
scatter (x(1,:), y(1,:), 's', 'MarkerFaceColor', [102, 215, 209]./255)
's' will produce a square marker, for row element. Similarly, for other rows, you can specify the marker shape
scatter (x(2,:), y(2,:), '+', 'MarkerFaceColor', [102, 215, 209]./255)
A complete list of markers supported by MATLAB is given here: https://www.mathworks.com/help/matlab/ref/scatter.html#btrj9jn-1-mkr.
Also, you can refer to this FEX submission to get an idea on how to draw custom markers: https://www.mathworks.com/matlabcentral/fileexchange/39487-custom-marker-plot
  2 Kommentare
Kundera
Kundera am 17 Jun. 2018
Hi, I think you misunderstood my question. If you try to plot the few lines of code I previously have plotted, my problem is that I finally want to have for example Marker 'o' for three points (each of them have a different color). And correct, I need to do it for 12 rows.
In other words, I am not looking for a solution like this:
scatter (x(2,:), y(2,:), '+', 'MarkerFaceColor', [102, 215, 209]./255)
Because I want these points to have the same color, but each of them having a different masker.
dpb
dpb am 17 Jun. 2018
That is the original problem then -- you can only do that by a single marker for every point because in HG2 each line or scatter object has only a single linestyle associated with it.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by