view — Set or query 3-D camera view angles with MATLAB-compatible view call forms.
view reads or updates azimuth/elevation camera orientation for current or specified axes. It supports MATLAB-compatible forms such as view(2), view(3), view([az el]), and view(az, el).
Syntax
[az, el] = view(...)
angles = view()
angles = view(ax)
angles = view([az el] | preset)
angles = view(az, el)
angles = view(ax, [az el] | preset)
angles = view(ax, az, el)Inputs
angles- Type
NumericArray- Required
- Yes
- Description
- Two-element [az el] vector or preset value 2/3.
ax- Type
AxesHandle- Required
- Yes
- Description
- Axes handle to query.
az- Type
NumericScalar- Required
- Yes
- Description
- Azimuth in degrees.
el- Type
NumericScalar- Required
- Yes
- Description
- Elevation in degrees.
ax- Type
AxesHandle- Required
- Yes
- Description
- Axes handle to set.
Returns
az- Type
NumericScalar- Description
- Azimuth angle in degrees.
el- Type
NumericScalar- Description
- Elevation angle in degrees.
angles- Type
NumericArray- Description
- Current or assigned view angles as [az el].
Returned values from view depend on how many outputs the caller requests.
Errors
RunMat:view:InvalidArgument- When
- Arguments are malformed, wrong arity, wrong shape, or unsupported preset.
- Message
view: invalid argument
RunMat:view:InvalidAxes- When
- Axes target is invalid or no longer exists.
- Message
view: invalid axes target
RunMat:view:Internal- When
- Internal plotting state operation fails.
- Message
view: internal operation failed
RunMat:view:TooManyOutputs- When
- More than two outputs are requested.
- Message
view: too many output arguments
Behavior and execution
view with no angle arguments queries the current [az el] pair.
view(2) selects the standard top-down 2-D camera and view(3) restores the standard 3-D camera preset.
Explicit azimuth/elevation values can be passed as two scalars or as a two-element vector.
View state is subplot-local and does not leak across different axes in a subplot grid.
Axes handles can be passed explicitly so camera changes target a specific subplot rather than whichever axes happens to be current.
Typed-integer angles and numeric axes aliases are independently gated RunMat extensions. Integer angles must be exactly representable in the renderer's single-precision camera state before any plot mutation.
Three-element line-of-sight vectors and arrays of axes handles are not implemented. The documented two-output angle query is supported.
With two explicitly requested outputs, [az,el] = view(...) returns scalar doubles for the current or assigned camera angles. With one explicitly requested output, the RunMat-only vector-output extension returns [az el]; strict MATLAB mode rejects this extension rather than claiming a MATLAB view-matrix result. Zero outputs still query or update the selected axes.
The existing shared camera state stores angles in single precision. Floating inputs must remain finite across that renderer boundary; typed integers must round-trip exactly. Query outputs are double representations of the stored values.
These graphics metadata controls require host numeric values: no implicit device download or numeric acceleration is declared. Handles refer to local axes state, not transferable worker/foreign graphics ownership. Output admission and numeric parsing precede default-axes creation.
Figure observers are notified through the shared axes-state owner.
Examples
Set an explicit 3-D camera angle
[X, Y] = meshgrid(linspace(-2, 2, 60), linspace(-2, 2, 60));
Z = sin(X.^2 + Y.^2);
surf(X, Y, Z);
view(45, 30);Use MATLAB-style view presets
[X, Y] = meshgrid(linspace(-3, 3, 40), linspace(-3, 3, 40));
Z = sin(X) .* cos(Y);
surf(X, Y, Z);
view(2);
view(3);Query a subplot-local camera
ax = subplot(1, 2, 2);
plot3(cos(0:0.1:5), sin(0:0.1:5), 0:0.1:5);
view(ax, [60 20]);
get(ax, 'View')Expected output:
% Returns a 1x2 vector [60 20]Using view with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how view changes the result.
Run a small view example, explain the result, then change one input and compare the output.
FAQ
What do azimuth and elevation mean in view(az, el)?⌄
Azimuth is the horizontal rotation around the z-axis (0° looks along the y-axis toward the origin). Elevation is the angle above the x-y plane (0° is level, 90° is directly overhead). view(45, 30) gives the classic isometric-ish perspective for 3-D surfaces.
How do I reset to the default 2-D or 3-D view?⌄
view(2) sets the camera to top-down (azimuth 0, elevation 90) — useful for looking at a surface as a heatmap. view(3) restores the default 3-D camera at [-37.5, 30], which is the standard MATLAB 3-D preset.
Can I set different view angles per subplot?⌄
Yes. View state is subplot-local. Pass the axes handle explicitly to target a specific panel.
ax1 = subplot(1, 2, 1); surf(X, Y, Z); view(ax1, 0, 90);
ax2 = subplot(1, 2, 2); surf(X, Y, Z); view(ax2, 45, 30);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.