MATLAB Figures and Related Commands

Graphics created in MATLAB are figure objects. There are several generic commands used to manipulate figures regardless of how they were created.


Figure

To create a new figure window, try:

% Automatically named sequentially.
figure;

% Specifically named.
figure(Title="foo");


Hold

Use hold on to accumulate plots into the same graphic. This is then disabled by hold off.


View

To adjust the camera used to render a figure, try:

view([45 30]);

The arguments are azimuth and elevation angles, respectively.


Labels

For a 3D figure, try:

xlabel('x');
ylabel('y');
zlabel('z');

zlabel is not appropriate for a 2D figure.


Axis

By default, MATLAB tries to show figures with a smart scaling. Use axis equal to force axes to be equally scaled.


Title

title("Figure Title");


Legend

plot(spectra)
legend(starnames)

Plots in a figure are strictly ordered by insertion. The legend must use the same order.


CategoryRicottone