How can I change the line color in a graph using stem?
4 views (last 30 days)
Show older comments
Alejandro Franco
on 28 Feb 2015
Commented: Star Strider
on 1 Mar 2015
Hello. I need to change the color of my graph when the value exceeds a certain limit. I use stem for the graph.
% Create figure figure1 = figure('Name','Peak Distortion','Color',[0 0 0]);
% Create axes
axes1 = axes('Parent',figure1,... 'Position',[0.130625 0.904793101727064 0.774375 0.0790343915343916],... 'Color',[0 0 0]);
% Uncomment the following line to preserve the Y-limits of the axes
ylim(axes1,[0 40]);
hold(axes1,'all');
% Create stem
stem(X1,Y1,'Marker','none','Color',[0 0.498039215803146 0],'Parent',axes1);
% Create ylabel
ylabel('Vib 1','VerticalAlignment','top','Color',[1 1 1],'Rotation',0);
when the value of Y1 is greater than 30 I want a red line in my plot any sugestion thanks
0 Comments
Accepted Answer
Star Strider
on 28 Feb 2015
This works, although you’ll have to adapt it slightly to fit with your existing plot calls (insert: 'Parent',axes1):
X1 = 1:25;
Y1 = randi(50, 1, 25);
figure(1)
stem(X1,Y1,'Marker','none','Color',[0 0.498039215803146 0]);
hold on
stem(X1(Y1>30),Y1(Y1>30),'Marker','none','Color',[1 0 0]);
hold off
I assume what you want is the stem colour to change, since you’re not using markers. My code here simply overplots the data that are >30 with a red stem line in the second stem call.
2 Comments
More Answers (0)
See Also
Categories
Find more on Stem Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!