RunMat
GitHub

view — Control 3-D camera angles for surfaces and spatial plots using azimuth/elevation views and MATLAB view semantics.

view reads or updates the camera orientation for the current axes or an explicit axes handle. In RunMat it stores subplot-local azimuth and elevation state, supports MATLAB view(2), view(3), view([az el]), and view(az, el) call forms, and integrates with the same handle/property system used by get and set.

How view works in RunMat

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

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

These functions work well alongside view. Each page has runnable examples you can try in the browser.

plot3, scatter3, surf, zlabel, get, set

More plotting resources

Open-source implementation

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

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.

  • Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
  • Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
  • A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.

Getting started · Benchmarks · Pricing

Try RunMat for free

Open the sandbox and start running MATLAB code in seconds. No account required.