STEM3 plot with different colors
Mostrar comentarios más antiguos
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 comentario
Katherine Zheng
el 14 de Nov. de 2022
Did you manage to figure out? I want to achieve what you decribed as well.
Respuestas (2)
Andrew Newell
el 19 de Feb. de 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
el 2 de Mzo. de 2011
0 votos
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 comentario
Dean Weems
el 11 de Mzo. de 2011
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!