MATLAB: Is it possible to turn off or suppress the X, Y, or Z axis in a plot

invisibleMATLABvisible

I'm creating a series of stacked subplots that all use the same X-axis. I'd like to turn off the X-axis in the top plots and only display it in the bottom plot. For example:
|
| <-----upper plot (with only Y axis)
|
|
| <----- lower plot(with both axes)
|
---------------------------
Is this possible in MATLAB?

Best Answer

MATLAB does not directly support this functionality; however, you can approximate it using Handle Graphics. For example:
%---------------------------------------------

% Example of how to turn off the X-axis in the
% top subplot.
% Define some data
x = linspace(0,8*pi,100);
y1 = sin(x);
y2 = cos(x);
% Create the plots
ax(1) = subplot(211);
plot(x,y1)
ax(2) = subplot(212);
plot(x,y1)
% Set the X-axis tick locations and limits of
% each plot to the same values
set(ax,'XTick',get(ax(1),'XTick'), ...
'XLim',get(ax(1),'XLim'))
% Turn off the X-tick labels in the top axes
set(ax(1),'XTickLabel','')
% Set the color of the X-axis in the top axes
% to the axes background color
set(ax(1),'XColor',get(gca,'Color'))
% Turn off the box so that only the left
% vertical axis and bottom axis are drawn
set(ax,'box','off')
%---------------------------------------------
This example simply changes the color of the top X-axis to match the color of the axes. One drawback with this is that you can see discontinuities in the Y-axis and line where the X-tick marks are.
An enhancement request has been submitted to our development staff requesting that an X/Y/ZAxisVisible property be added to MATLAB.