While others have provided you exactly what you've asked for (how to make an axes or figure the current one). My preferred way for dealing with this, is to explicitly specify the parent of your plot in the call to plot3
.
If you look at the documentation, you will see that you can specify the parent axes as the first parameter to the function. If looks like you attempted to do this in your example, but you provided a handle to a figure rather than an axes.
f = figure()
ax = axes('Parent', f)
im = plot3(ax, X, Y, Z);
Alternately, I prefer the explicit solution
im = plot3(X, Y, Z, 'Parent', ax)
The nice thing about this explicit parameter/value specification of the parent is that it is accepted by all graphics objects. Functions like plot
and plot3
are actually helper functions that wrap the functionality of line
and allow for the convention of passing the parent first. The parameter/value approach is widely accepted regardless of whether you're working with a higher level function (plot
, plot3
, imshow
) or the lower level objects (line
, image
, etc.)
The two benefits here are that you remove the overhead of MATLAB trying to figure out where to put your plot and also, it prevents MATLAB from having to change which figure is currently displayed, forcing a re-rendering which is one of MATLAB's slowest tasks.
aa = findobj(gcf, 'type', 'axes')
, then (2)cellfun(@(x) disp(x), get(aa, 'position'))
, from which we can tell which subplot is which, then (3)axes(aa(2))
for example, to make the second axes object current. – Runofthemill