How to freeze the range of y-axis on an axes on gui?

72 views (last 30 days)
I am trying to plot the time audio signal using plot(handles.axes1, x) which works fine. The problem is that I cannot make the make the range of a y-axis fix at [-1 1]. I try to set the YLim to be [-1, 1], and YLimMode to be 'manual' both in property windows settings using gui and also in callcall back

Answers (3)

Dario Mangoni
Dario Mangoni on 11 Dec 2018
Edited: Dario Mangoni on 11 Dec 2018
Currently (at R2018b) this operation is made easy through 'axis manual' command.
figure;
hold on;
plot(1,1,'+')
plot(2,2,'+')
axis manual
plot(50,50,'+')
The point (50,50) is not in view because axis limits has been retained.
See axis documentation for more options.

Matt J
Matt J on 28 Aug 2015
Edited: Matt J on 28 Aug 2015
It is not enough to set YLimMode to 'manual'. You need to apply "hold on" as Geoff mentioned. However, you can still use CLA to clear the plot between re-renderings, like in the example below.
axis([0,11,-1,1]);
h=gca;
hold on
h.YLimMode='manual';
for i=1:100,
plot(1:10,rand(1,10));
pause(.3);
drawnow
cla
end
hold off

Geoff Hayes
Geoff Hayes on 2 Feb 2015
Try using ylim which will allow you to set the y-axis limits. In your case, you could do something like
ylim(handles.axes1,[-1 1]);
In order to keep these limits, you may need to call
hold(handles.axes1,'on');
so that you return the current properties of the axes before a new plot is added to it.
  2 Comments
MatlabNewbie01232015
MatlabNewbie01232015 on 3 Feb 2015
Thank for helping me out. The problem is the plot becomes a mess because I try to display the output of an audio file segment by segment. Is there anyway I can clear what on the plot but still keep the axes' range?
Geoff Hayes
Geoff Hayes on 4 Feb 2015
Why not just replace the x and y data from the previous segment? Something like
% plot the first segment
h = plot(x,y);
% use the handle from plot, h, to update with the new segment data
set(h,'XData',xNewSeg,'YData',yNewSeg);
where xNewSeg and yNewSeg are the x and y data from the new segment.

Sign in to comment.

Categories

Find more on Geographic 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!