MATLAB: Add markers to stem plot above a threshold
markersstem plot
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?
Best Answer
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
If you check thexLimMode after running your code, you will see that it has changed back toauto after theplot() statement. You need tohold() the axis to stop it from changing automatically.
fig = figure;
ha1 = axes;
ha1.Position = [0.5 0.5 0.3 0.3]
ha1.XLim = [-10 -5];
ha1.YLim = [-5 -1];
set(ha1,'xlimMode','manual');
set(ha1,'ylimMode','manual');
[x,y] = ginput;
hold(ha1); %<--- this line will prevent automatic changes.
Best Answer