Function Reference
— Function File: axis (limits)

Set axis limits for plots.

The argument limits should be a 2, 4, or 6 element vector. The first and second elements specify the lower and upper limits for the x axis. The third and fourth specify the limits for the y axis, and the fifth and sixth specify the limits for the z axis.

Without any arguments, axis turns autoscaling on.

With one output argument, x=axis returns the current axes

The vector argument specifying limits is optional, and additional string arguments may be used to specify various axis properties. For example,

          axis ([1, 2, 3, 4], "square");

forces a square aspect ratio, and

          axis ("labely", "tic");

turns tic marks on for all axes and tic mark labels on for the y-axis only.

The following options control the aspect ratio of the axes.

"square"
Force a square aspect ratio.
"equal"
Force x distance to equal y-distance.
"normal"
Restore the balance.

The following options control the way axis limits are interpreted.

"auto"
Set the specified axes to have nice limits around the data or all if no axes are specified.
"manual"
Fix the current axes limits.
"tight"
Fix axes to the limits of the data (not implemented).

The option "image" is equivalent to "tight" and "equal".

The following options affect the appearance of tic marks.

"on"
Turn tic marks and labels on for all axes.
"off"
Turn tic marks off for all axes.
"tic[xyz]"
Turn tic marks on for all axes, or turn them on for the specified axes and off for the remainder.
"label[xyz]"
Turn tic labels on for all axes, or turn them on for the specified axes and off for the remainder.
"nolabel"
Turn tic labels off for all axes.
Note, if there are no tic marks for an axis, there can be no labels.

The following options affect the direction of increasing values on the axes.

"ij"
Reverse y-axis, so lower values are nearer the top.
"xy"
Restore y-axis, so higher values are nearer the top.

If an axes handle is passed as the first argument, then operate on this axes rather than the current axes.

Demonstration 1

The following code

 t=0:0.01:2*pi; x=sin(t);

 subplot(221);    title("normal plot");
 plot(t, x);

 subplot(222);    title("square plot");
 axis("square");  plot(t, x);

 subplot(223);    title("equal plot");
 axis("equal");   plot(t, x);
 
 subplot(224);    title("normal plot again");
 axis("normal");  plot(t, x);

Produces the following figure

Demonstration 2

The following code

 t=0:0.01:2*pi; x=sin(t);

 subplot(121);   title("ij plot");
 axis("ij");     plot(t, x);

 subplot(122);   title("xy plot");
 axis("xy");     plot(t, x);

Produces the following figure

Demonstration 3

The following code

 t=0:0.01:2*pi; x=sin(t);

 subplot(331);   title("x tics & labels");
 axis("ticx");   plot(t, x);

 subplot(332);   title("y tics & labels");
 axis("ticy");   plot(t, x);

 subplot(334);     title("x & y tics, x labels");
 axis("labelx","tic");   plot(t, x);

 subplot(335);     title("x & y tics, y labels");
 axis("labely","tic");   plot(t, x);

 subplot(337);     title("x tics, no labels");
 axis("nolabel","ticx");   plot(t, x);

 subplot(338);     title("y tics, no labels");
 axis("nolabel","ticy");   plot(t, x);

 subplot(333);     title("no tics or labels");
 axis("off");    plot(t, x);

 subplot(336);     title("all tics but no labels");
 axis("nolabel","tic");    plot(t, x);

 subplot(339);     title("all tics & labels");
 axis("on");       plot(t, x);

Produces the following figure

Demonstration 4

The following code

 t=0:0.01:2*pi; x=sin(t);

 subplot(321);    title("axes at [0 3 0 1]")
 axis([0,3,0,1]); plot(t, x);

 subplot(322);    title("auto");
 axis("auto");    plot(t, x);

 subplot(323);    title("manual");
 plot(t, x, ";sine [0:2pi];"); hold on;
 axis("manual");
 plot(-3:3,-3:3, ";line (-3,-3)->(3,3);"); hold off;

 subplot(324);    title("axes at [0 3 0 1], then autox");
 axis([0,3,0,1]); axis("autox");
 plot(t, x, ";sine [0:2pi];");

 subplot(325);    title("axes at [3 6 0 1], then autoy");
 axis([3,6,0,1]); axis("autoy");
 plot(t, x, ";sine [0:2p];");

 subplot(326);    title("tight");
 axis("tight");   plot(t, x);
 % The last plot should not have any whitespace outside the data
 % limits, but "tight" isn't implemented yet.

Produces the following figure