STEM3 plot with different colors

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 个评论

Did you manage to figure out? I want to achieve what you decribed as well.

请先登录,再进行评论。

回答(2 个)

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
Luz 2011-3-2

0 个投票

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!

类别

帮助中心File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

产品

标签

Community Treasure Hunt

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

Start Hunting!

Translated by