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
Katherine Zheng
2022년 11월 14일
Did you manage to figure out? I want to achieve what you decribed as well.
답변 (2개)
Andrew Newell
2011년 2월 19일
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
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!