Navigation

Operators and Keywords

Function List:

C++ API

: axis ()
: axis ([x_lo x_hi])
: axis ([x_lo x_hi y_lo y_hi])
: axis ([x_lo x_hi y_lo y_hi z_lo z_hi])
: axis ([x_lo x_hi y_lo y_hi z_lo z_hi c_lo c_hi])
: axis (option)
: axis (option1, option2, …)
: axis (hax, …)
: limits = axis ()

Set axis limits and appearance.

The argument limits should be a 2-, 4-, 6-, or 8-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, the fifth and sixth specify the limits for the z-axis, and the seventh and eighth specify the limits for the color axis. The special values -Inf and Inf may be used to indicate that the limit should be automatically computed based on the data in the axis.

Without any arguments, axis turns autoscaling on.

With one output argument, limits = axis returns the current axis limits.

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

The following options control the aspect ratio of the axes.

"square"

Force a square axis aspect ratio.

"equal"

Force x-axis unit distance to equal y-axis (and z-axis) unit distance.

"normal"

Restore default aspect ratio.

The following options control the way axis limits are interpreted.

"auto"
"auto[xyz]"

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.

"image"

Equivalent to "tight" and "equal".

The following options affect the appearance of tick marks.

"tic[xyz]"

Turn tick marks on for all axes, or turn them on for the specified axes and off for the remainder.

"label[xyz]"

Turn tick labels on for all axes, or turn them on for the specified axes and off for the remainder.

"nolabel"

Turn tick labels off for all axes.

Note: If there are no tick marks for an axis then there can be no labels.

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

"xy"

Default y-axis, larger values are near the top.

"ij"

Reverse y-axis, smaller values are near the top.

The following options affects the visibility of the axes.

"on"

Make the axes visible.

"off"

Hide the axes.

If the first argument hax is an axes handle, then operate on this axes rather than the current axes returned by gca.

Example 1: set X/Y limits and force a square aspect ratio

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

Example 2: enable tick marks on all axes, enable tick mark labels only on the y-axis

axis ("tic", "labely");

See also: xlim, ylim, zlim, caxis, daspect, pbaspect, box, grid.

Demonstration 1

The following code

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

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

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

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

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

Produces the following figure

Figure 1

Demonstration 2

The following code

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

 subplot (121);
  plot (t, x);
  title ({"axis ij", "Y-axis reversed"});
  axis ("ij");
  legend ("sine");

 subplot (122);
  plot (t, x);
  title ("axis xy");
  title ({"axis ij", "Y-axis normal"});
  axis ("xy");
  legend ("sine");

Produces the following figure

Figure 1

Demonstration 3

The following code

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

 subplot (331);
  plot (t, x);
  title ("x ticks and labels");
  axis ("ticx");

 subplot (332);
  plot (t, x);
  title ("y ticks and labels");
  axis ("ticy");

 subplot (333);
  plot (t, x);
  title ("axis off");
  axis ("off");

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

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

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

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

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

 subplot (339);
  plot (t, x);
  title ("all ticks and labels");
  axis ("on");

Produces the following figure

Figure 1

Demonstration 4

The following code

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

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

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

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

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

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

 subplot (326);
  plot (t, sin(t), t, -2*sin(t/2));
  axis ("tight");
  title ("tight");

Produces the following figure

Figure 1

Demonstration 5

The following code

 clf;
 x = 0:0.1:10;
 plot (x, sin(x));
 axis image;
 title ({"image", 'equivalent to "tight" & "equal"'});

Produces the following figure

Figure 1

Demonstration 6

The following code

 clf;
 colormap ("default");
 [x,y,z] = peaks (50);
 x1 = max (x(:));
 pcolor (x-x1, y-x1/2, z);
 hold on;
 [x,y,z] = sombrero ();
 s = x1 / max (x(:));
 pcolor (s*x+x1, s*y+x1/2, 5*z);
 axis tight;

Produces the following figure

Figure 1

Demonstration 7

The following code

 clf;
 x = -10:10;
 plot (x,x, x,-x);
 set (gca, "yscale", "log");
 legend ({"x >= 1", "x <= 1"}, "location", "north");
 title ("ylim = [1, 10]");

Produces the following output

warning: axis: omitting non-positive data in log plot

and the following figure

Figure 1

Demonstration 8

The following code

 clf;
 loglog (1:20, "-s");
 axis tight;

Produces the following figure

warning: axis: omitting non-positive data in log plot

and the following figure

Figure 1

Demonstration 9

The following code

 clf;
 x = -10:0.1:10;
 y = sin (x)./(1 + abs (x)) + 0.1*x - 0.4;
 plot (x, y);
 set (gca, "xaxislocation", "origin");
 set (gca, "yaxislocation", "origin");
 box off;
 title ({"no plot box", "xaxislocation = origin, yaxislocation = origin"});

Produces the following figure

warning: axis: omitting non-positive data in log plot

and the following figure

Figure 1

Demonstration 10

The following code

 clf;
 x = -10:0.1:10;
 y = sin (x)./(1+abs (x)) + 0.1*x - 0.4;
 plot (x, y);
 set (gca, "xaxislocation", "origin");
 set (gca, "yaxislocation", "left");
 box off;
 title ({"no plot box", "xaxislocation = origin, yaxislocation = left"});

Produces the following figure

warning: axis: omitting non-positive data in log plot

and the following figure

Figure 1

Demonstration 11

The following code

 clf;
 x = -10:0.1:10;
 y = sin (x)./(1+abs (x)) + 0.1*x - 0.4;
 plot (x, y);
 title ("no plot box");
 set (gca, "xaxislocation", "origin");
 set (gca, "yaxislocation", "right");
 box off;
 title ({"no plot box", "xaxislocation = origin, yaxislocation = right"});

Produces the following figure

warning: axis: omitting non-positive data in log plot

and the following figure

Figure 1

Demonstration 12

The following code

 clf;
 x = -10:0.1:10;
 y = sin (x)./(1+abs (x)) + 0.1*x - 0.4;
 plot (x, y);
 set (gca, "xaxislocation", "bottom");
 set (gca, "yaxislocation", "origin");
 box off;
 title ({"no plot box", "xaxislocation = bottom, yaxislocation = origin"});

Produces the following figure

warning: axis: omitting non-positive data in log plot

and the following figure

Figure 1

Demonstration 13

The following code

 clf;
 x = -10:0.1:10;
 y = sin (x)./(1+abs (x)) + 0.1*x - 0.4;
 plot (x, y);
 set (gca, "xaxislocation", "top");
 set (gca, "yaxislocation", "origin");
 box off;
 title ({"no plot box", "xaxislocation = top, yaxislocation = origin"});

Produces the following figure

warning: axis: omitting non-positive data in log plot

and the following figure

Figure 1

Package: octave