STEM3 plot with different colors
Afficher commentaires plus anciens
I have a matrix that I wish to plot using STEM3, but I want to color the stem according it according to its value. I don't see any method by which to accomplish this task. Any recommendations.
1 commentaire
Katherine Zheng
le 14 Nov 2022
Did you manage to figure out? I want to achieve what you decribed as well.
Réponses (2)
Andrew Newell
le 19 Fév 2011
I think the short answer is - not easily. Let's take this example from the stem3 documentation:
figure
X = linspace(0,1,10);
Y = X./2;
Z = sin(X) + cos(Y);
h = stem3(X,Y,Z,'fill');
view(-25,30)
If you now type
get(h,'Children')
you get two handles, one of which is all the stems and other is all the lines. These handles don't have any children. I think this is related to the larger problem that you can't ungroup graphical objects in Matlab.
There might be a workaround, because with the data brushing tool you can select one point at a time and change its color - although this changes the color of both stem and line. Still, it means that somewhere (perhaps in the Java code) the individual points are accessible.
Luz
le 2 Mar 2011
0 votes
I created this simple code for changing colors in 3 sets of data in a stem3 graph.
%Random data in vectors
L = [1 2 3 4 2 6 7]
M=[2 6 4 5 7 8 9]
O=[3 5 8 9 4 7 5]
s=[1,2,3,4,5,6,7]
f=[2,4,6,8,2,4,6]
%I use stem3 and hold on
h= stem3(s,f,L)
hold on
m= stem3(s,f,M)
hold on
o= stem3(s,f,O)
hold off
%Now I can include the colors I want for each set of data
set(h(1),'MarkerFaceColor','red')
set(m(1),'MarkerFaceColor','green')
set(o(1),'MarkerFaceColor','yellow')
%I hope it helps!
1 commentaire
Dean Weems
le 11 Mar 2011
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!