Add markers to stem plot above a threshold

12 visualizaciones (últimos 30 días)
Steffen Kristiansen
Steffen Kristiansen el 19 de Mayo de 2020
Editada: Cris LaPierre el 19 de Mayo de 2020
Hello,
I have a stem plot where I have removed all the markers. Now I want to add cross markers to the stems that exceed a certain threshold on the y-axis.
Is there a way to do that?

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 19 de Mayo de 2020
Editada: Cris LaPierre el 19 de Mayo de 2020
This would have to be done in two steps. First, create your stem plot with no markers, then plot a second stem plot on top of it for just the data that meets your requirements. Here's a simple example.
% Create your data. You will need x for the second plot.
x = 1:7;
y=[2 3 2 6 2 5 1];
% Find data points that exceed your threshold
ind = y>=5;
%Create the first stem plot. Specify the color to use in both stem plots
stem(x,y,"Marker","none",'Color','b')
% Add a second stem plot on top of the first.
hold on
stem(x(ind),y(ind),'Color','b','Marker',"x","LineStyle","none")
hold off
xlim([0,8])
ylim([0,8])

Más respuestas (1)

Johannes Hougaard
Johannes Hougaard el 19 de Mayo de 2020
Either by plotting the stem plot in two steps (over and under cutoff)
data = rand(18,1)+randperm(18)';
figure;axes;hold on;
cutoff = 12;
stem(find(data <= cutoff),data(data <= cutoff),'Marker','none','Color',[0 0.4470 0.7410]);
stem(find(data > cutoff),data(data > cutoff),'b','Marker','x','Color',[0 0.4470 0.7410]);
Or by adding x'es as a text
figure;
sh = stem(data,'Marker','none');
text(sh.XData(sh.YData > cutoff),sh.YData(sh.YData > cutoff),'x','color',get(sh,'Color'),...
'HorizontalAlignment','center','VerticalAlignment','bottom');

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by