You are on page 1of 2

% Create some data to work with

x = 0.5:.25:1.5;
y1 = [0 0 0 0.004 0.005];
y2 = [0.002 0.001 0.003 0.003 0.006];
y3 = [0.002 0.002 0.004 0.004 0.004];
y4 = [0.003 0.003 0.007 0.008 0.005];
y5 = [0.007 0.005 0.004 0.009 0.005];
% Plot on the left and right y axes
figure
ax1 = axes;
yyaxis left % see [1]
mesh(x,y1)
axis([0.5 1.5 0 0.006])
pause(0.1) % see [3]
% set the y(left) and x tick values, make them permanent
% This is the tricky part and shoudl receive a lot of
thought when
% you adapt this to your code...
ax1.XTickMode = 'manual';
ax1.YTickMode = 'manual';
ax1.YLim = [min(ax1.YTick), max(ax1.YTick)]; % see [4]
ax1.XLimMode = 'manual';
grid(ax1,'on')
ytick = ax1.YTick;
yyaxis right % see [1]

mesh(x,y2)
axis([0.5 1.5 0 0.006])

% create 2nd, transparent axes


ax2 = axes('position', ax1.Position);

mesh(ax2,x,y3, 'k')
axis([0.5 1.5 0 0.006])

pause(0.1) % see [3]


ax2.Color = 'none';
grid(ax2, 'on')
% Horizontally scale the y axis to alight the grid (again,
be careful!)
ax2.XLim = ax1.XLim;
ax2.XTick = ax1.XTick;
ax2.YLimMode = 'manual';
yl = ax2.YLim;
ax2.YTick = linspace(yl(1), yl(2), length(ytick)); %
see [2]
% horzontally offset y tick labels
ax2.YTickLabel = strcat(ax2.YTickLabel, {' '});

You might also like