MATLAB: Can I create multiple stem axes using stem3

3d plotsMATLABplottingstem3

I would like to have stem3 generate stems off more than one axis, if possible.
If we can say the "default" vertical stem connects point(x,y,z) to the z=min(z) plane, then can we create a stem from point(x,y,z) to some other plane, say, to lie horizontally toward x=max(x)? The desire is to either rotate the default stems to another axis, or (better) add a new set of orthogonally oriented stems in conjunction with the default stems.
For particular populations, this may help visualize the depth of the data field.
Thanks, MATLABers!

Best Answer

One approach:
x = randi(9, 1, 5); % Create Data


y = randi(9, 1, 5); % Create Data
z = randi(9, 1, 5); % Create Data
x = x(:); % Force Columns
y = y(:);
z = z(:);
figure(1)
stem3(x, y, z)
axis([0 10 0 10 0 10]) % The ‘axis’ Call Must Be Placed Here
hold on
plot3([ones(size(x))*max(xlim) x]', [y y]', [z z]', '-r')
plot3([x x]', [ones(size(y))*max(ylim) y]', [z z]', '-g')
hold off
grid on
xlabel('X')
ylabel('Y')
zlabel('Z')
This works the same way drawing horizontal lines works with 2D plots, although it requires slightly different coding. The axis call has to be placed just after the stem call for the horizontal lines to plot correctly, since they use the existing axis limits.
Experiment to get the result you want.
EDIT Added plot.