MATLAB Answers

0

Why do axes limits keep changing when using axis commands in MATLAB R2014b?

I am plotting a series of lines on an axes. After I have plot one line using the 'line' function, I use the command:
axes tight
The above command sets the axes limits to a specific value, after which I add additional lines using additional 'line' commands. In MATLAB R2014a, adding additional plots did not change the axes limits. However in MATLAB R2014b, adding additional plots changes the axes limits each time I add a new plot. Why is this so?

Products


Release

R2014b

1 Answer

Answer by MathWorks Support Team on 25 Aug 2014
 Accepted Answer

In R2014a and earlier, if you set the axis limits using an 'axis tight' or an 'axis image' command, then the calculated axis limits do not change. If you add new data to the axes outside of the current axis limits, then the limits do not automatically update to encompass the data.
Starting in R2014b, if you use these commands and afterwards add new data to the axes, then the axis limits automatically update to encompass the new data. For example, this code sets the axis limits using the 'axis tight' command, and then adds new data to the graph.
line([10 20],[3 4],'Color','red')
axis tight
line([0 10],[1 2],'Color','blue')
 
Starting in R2014b, the limits update to encompass both lines.
 
In R2014a and earlier, the limits do not update so the blue line is not visible in the axes.
In R2014a and earlier, these 'axis' commands set the axis limit modes (XLimMode, YLimMode, and ZLimMode) to 'manual'. When the limit modes are manual, the limits do not update to reflect changes in the data. Starting in R2014b, these 'axis' commands set the axis limit modes to 'auto'. When the limit modes are auto, the limits automatically update to reflect changes in the data.
To keep the axis limits from automatically updating, append 'manual' to the end of the axis command. For example, 'axis tight manual'. The 'manual' option sets the limit modes to manual, as in previous releases, so that the limits do not automatically update. For example, this code does not update the limits to encompass the second blue line.
line([10 20],[3 4], 'Color', 'red');
axis tight manual;
line([0 10],[1 2], 'Color', 'blue');

  1 Comment

I really don't understand what is the logic behind the changing the default behavior of a function or script. Now I have to go all of my codes, (maybe hundredths different scripts) and need to change "axis tight" to "axis tight manual" "axis tight" should be same and if somebody wants it automatic then needs to call "axis tight auto;" or somethink like that. I believe that should be the correct logic.
The worse part is when I send my code someone else who use older version will see funny figures.

Sign in to comment.