To understand what is happening, it is important to know that for most MATLAB build commands, unless axes
explicitly specified in the command, the current axes
used by default. If no axes
exists, one is created and its appearance is completely controlled by the charting team. If the current axes
object exists, usually the plot command will not change the appearance of the axes
object, since in theory you already configured it.
hold on
changes the NexPlot
property for the current axes so that the next object that has been drawn does not overwrite previous objects. If axes
does not currently exist, hold
will implicitly create the axes
object. The default view for this new axis object is a 2D XY view. Since the axes
object now already exists when you call mesh
, it just uses the current view (and other axes
parameters), rather than changing it.
In case you don't call hold on
, there are no axes
before calling mesh
, so mesh
creates an axes
object on its own with properties that are ideal for rendering the mesh. This includes using a three-dimensional view and displaying grid lines.
You can manually change the axes
properties created by hold on
by calling view(3)
to use the default 3D view and grid on
to enable grid labels
figure hold on % Make it the default 3D view view(3) % Show the gridlines grid on mesh(X, Y, U)
Suver source share