Prevent aggressive autoscaling in Matlab

Let's say I have the following Matlab code:

figure; a=plot(1:10); %A pause(); set(a,'ydata',1:2:20); %B pause(); set(a,'ydata',1:10); %C 

In (A), the vertical range of my graph is [1,10].
On (B), the vertical range of my graph is [0.20].
At (C) the vertical range is again [1,10].

I like that the plot automatically scales from step (A) to (B). I don't like autoscaling from (B) to (C) - it causes things to skip too much.

Is there a way to set the graph scale for expansion but never shrink?

In my opinion, it looks like this:

 set(gca,'XLimMode','auto_maxever'); 
+4
source share
1 answer

As far as I know, Matlab does not have a function like you describe, however ...

You can fine-tune the limits of X and Y by running the following command:

 set(gca,'XLim',[x1 x2], 'YLim',[y1 y2]); 

A quick alias for the same command:

 axis([xmin xmax ymin ymax]); 

You can also β€œfreeze” limits at any time by changing XLimMode and YLimMode from Auto to Manual :

 figure(); a=plot(1:10); %A pause(); set(a,'ydata',1:2:20); %B pause(); set(gca,'XLimMode','manual'); set(gca,'YLimMode','manual'); set(a,'ydata',1:10); %C 

Or you can use another alias that does the same:

 axis('manual'); 

If data is constantly being received, consider storing the axis boundaries before each update, and then perform manual scaling.

+6
source

Source: https://habr.com/ru/post/1435513/


All Articles