我有一个带有两个不同轴的图形。
我无法使轴对齐并使第二个轴不可见...我尝试了一些 if 事情(请参阅代码中的注释),但它们不起作用
clearvars
close all
clc
[X1,Y1,Z1] = peaks(25);
[X2,Y2,Z2] = peaks(25);
idx = find(X2>0);
Z2(idx) = NaN;
figure
set(gcf, 'Position', [0 0 800 800])
%%title
title('')
%%Create two axes
ax1 = axes;
pcolor(X1,Y1, Z1); shading flat
view(2)
ax2 = axes;
pcolor(X2,Y2, Z2); shading flat
%%link them
linkaxes([ax1,ax2]) %<==it didn't work
%ax1.XLim=[-3 3]; %<==I also tried this
%ax2.XLim=[-3 3];
%ax1.YLim=[-3 3];
%ax2.YLim=[-3 3];
%%Hide top axes
ax2.Visible = 'off'; %<== I thought that this would work
ax2.XTick = [];
ax2.YTick = [];
%%Colormaps
colormap(ax1, bone)
colormap(ax2, jet(26))
%%Add colorbars
set([ax1,ax2],'Position',[.17 .11 .685 .815]);
cb1 = colorbar(ax1,'position',[.08 .11 .03 .815]);
set(get(cb1,'ylabel'),'String','whatever','interpreter','latex', 'fontsize',20);
cb2 = colorbar(ax2,'position',[.92 .11 .03 .815]);
set(get(cb2,'ylabel'),'String','whatever','interpreter','latex', 'fontsize',20);
caxis(ax1,[-7 7])
caxis(ax2,[-5 5])
xlabel(ax1,'stuff')
ylabel(ax1,'other stuff')
注意:我使用的是 2017a