axis — Query or set axis limits, visibility, and aspect behavior in MATLAB and RunMat plotting.
axis queries or configures limits, visibility, and aspect behavior for the active axes. It supports four-, six-, and eight-element numeric limit vectors, target-handle queries, logical or numeric visibility controls, and command forms such as axis equal, axis image, axis auto, and axis tight.
Syntax
lim = axis()
lim = axis(ax)
axis([xmin xmax ymin ymax | ... cmin cmax])
axis(mode)
axis(visibility)Inputs
ax- Type
NumericScalar- Required
- Yes
- Description
- Existing axes handle whose limits are queried.
limits- Type
NumericArray- Required
- Yes
- Description
- Four-, six-, or eight-element x/y, x/y/z, or x/y/z/color limits vector.
mode- Type
StringScalar- Required
- Yes
- Description
- Mode token: 'equal'|'image'|'auto'|'tight'|'manual'|'ij'|'xy'|'on'|'off'.
visibility- Type
Any- Required
- Yes
- Description
- Axes visibility as on/off, logical true/false, or numeric 1/0.
Returns
lim- Type
NumericArray- Description
- Current x/y limits, with z limits included for a configured 3-D view.
Errors
RunMat:axis:InvalidArgument- When
- Axis argument is unsupported, malformed, non-finite, or has invalid bounds ordering.
- Message
axis: invalid argument
RunMat:axis:TooManyOutputs- When
- More than one output is requested.
- Message
axis: at most one output is supported
Behavior
axis() returns the current x and y limits as a four-element double vector, adding z limits when the axes contain 3-D data or have explicit z limits. Automatic z limits come from the plotted data, including before axis manual is called. axis(ax) queries the specified axes.
Four-, six-, and eight-element vectors set x/y, x/y/z, or x/y/z/color limits respectively. A -Inf lower endpoint or Inf upper endpoint retains the current data-fitted endpoint.
Automatic color endpoints use the scalar surface and scaled-image data governed by axes color limits. Direct-indexed and true-color images do not contribute. Scatter and mesh retain their separate color policies, and contour colors are already encoded in their vertices. Resident surfaces use retained range metadata; unavailable metadata produces an error before changing limits rather than downloading plot data.
Limit vectors accept all eight integer classes. Authoritative integer storage is validated before one deliberate conversion into host double graphics state, and later limit queries return double.
axis('on'), axis('off'), logical scalars, and numeric zero or one control axes visibility. Numeric visibility accepts all eight integer classes.
axis equal enables equal aspect behavior on the current axes.
axis image enables equal aspect behavior and returns limits to data-fitted bounds, matching MATLAB's axis equal plus axis tight behavior.
axis auto clears explicit limits and returns to automatic fitting.
axis tight uses data-driven fitting behavior while leaving figure-local plot contents unchanged.
Axis settings are subplot-local because they act on the active axes state.
GPU-resident limits and visibility controls reject before provider access because axis is a host graphics-state operation and exposes no interactive GPU-array input surface.
axis manual freezes the displayed limits; axis ij reverses the Y direction and axis xy restores normal direction without reversing stored limit endpoints. Multiple mode arguments, target-handle setters, and mode subsets are not supported.
Queries return host double row vectors. In RunMat mode setters can return logical true; MATLAB compatibility mode rejects an explicitly assigned setter output before mutation.
Placement and display
axis updates host-side plotting state. Numeric plot data can still use the existing GPU rendering fast paths.
axis returns host-side limit vectors and does not change array GPU residency.
axis performs no provider dispatch; resident limits and visibility controls reject rather than gathering.
These commands update shared graphics state and may notify figure observers. Numeric array acceleration remains with the original plotting/rendering pipeline; the commands do not launch array-provider kernels. Graphics display requires a browser graphics host or a desktop graphics host.
Control arguments must already be host values. Unsupported resident controls reject without provider downloads; existing resident plot buffers stay owned by their plotting/rendering paths. Invalid syntax and excess output requests are checked before creating or changing graphics state.
Examples
Set explicit x and y limits
plot(0:0.1:10, sin(0:0.1:10));
axis([0 10 -1 1]);Force equal axis scaling
t = linspace(0, 2*pi, 200);
plot(cos(t), sin(t));
axis equal;Display image data with square pixels
imagesc([1 2; 3 4]);
axis image;Return to automatic fitting inside a subplot
ax1 = subplot(1,2,1); plot(1:5,[1 4 2 5 3]); axis tight;
ax2 = subplot(1,2,2); plot(1:5,[5 4 3 2 1]); axis auto;Freeze limits and reverse the Y direction
plot([1 4],[2 8]); axis manual; before = axis();
hold on; plot([-100 100],[-200 200]); axis ij;Using axis with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how axis changes the result.
Run a small axis example, explain the result, then change one input and compare the output.
FAQ
How do I get equal aspect ratio so circles look like circles?⌄
Call axis equal after your plot command. This forces one unit on x to equal one unit on y in screen space. Without it, a circle drawn with plot(cos(t), sin(t)) will appear as an ellipse if the figure isn't perfectly square.
t = linspace(0, 2*pi, 200);
plot(cos(t), sin(t));
axis equal;How do I set manual axis limits?⌄
Pass a four-element vector: axis([xmin xmax ymin ymax]). For 3-D plots, use six elements: axis([xmin xmax ymin ymax zmin zmax]); append color limits for the eight-element form. Use -Inf for an automatic lower endpoint or Inf for an automatic upper endpoint. Explicit bounds override auto-fitting until you call axis auto.
What does axis tight actually do?⌄
axis tight clears explicit limits and uses the shared data-fitting path. RunMat currently uses this fitting path for axis auto as well; auto additionally clears equal-aspect mode. No separate automatic padding policy is promised.
What does axis image do?⌄
axis image combines equal aspect behavior with data-fitted limits. It is intended for image displays where pixels should appear square and the axes should fit the image data.
Related Plotting functions
2D Charts
area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem
Other
addpoints · ancestor · animatedline · autumn · axes · barh · bone · caxis · cla · clf · clim · colorcube · colororder · cool · copper · copyobj · cylinder · daspect · datacursormode · dataTipTextRow · drawnow · fcontour · figure · fill · fill3 · findobj · fsurf · gobjects · gray · groot · hgload · hgsave · hidden · histogram2 · hold · hot · inferno · isgraphics · ishandle · jet · line · lines · linkaxes · magma · openfig · opengl · pan · parula · patch · pink · plasma · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · spring · stackedplot · subtitle · summer · suptitle · text · textscatter · textscatter3 · triplot · turbo · viridis · waitbar · winter · wordcloud · xlabel · xlim · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · ylabel · ylim · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zlim · zoom
More plotting resources
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.