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

72 次查看(过去 30 天)
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

回答(3 个)

Dario Mangoni
Dario Mangoni 2018-12-11
编辑:Dario Mangoni 2018-12-11
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 2015-8-28
编辑:Matt J 2015-8-28
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 2015-2-2
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 个评论
MatlabNewbie01232015
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 2015-2-4
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Geographic Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by