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

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

NameTypeRequiredDefaultDescription
axAxesHandleYesAxes handle to query.
anglesNumericArrayYesTwo-element [az el] vector or preset value 2/3.
azNumericScalarYesAzimuth in degrees.
elNumericScalarYesElevation in degrees.
axAxesHandleYesAxes handle to set.

Returns

NameTypeDescription
anglesNumericArrayCurrent or assigned view angles as [az el].

Errors

IdentifierWhenMessage
RunMat:view:InvalidArgumentArguments are malformed, wrong arity, wrong shape, or unsupported preset.view: invalid argument
RunMat:view:InvalidAxesAxes target is invalid or no longer exists.view: invalid axes target
RunMat:view:InternalInternal plotting state operation fails.view: internal operation failed

How view works

  • 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.

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);

2D Charts

area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem

3D & Surface

contour · contour3 · contourf · mesh · meshc · plot3 · quiver · scatter3 · surf · surfc

Images

image · imagesc · imshow

Axes & Layout

axis · box · grid · sgtitle · subplot · title · zlabel

Appearance

colorbar · colormap · legend · shading

Handle Access

gca · gcf · get · set

Other

cla · clf · figure · fill3 · hold · patch · polarplot · print · suptitle · xline · yline

More plotting resources

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how view is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.