我正在尝试使用两个y轴,但是右侧轴上的刻度线与左侧轴上的刻度线不匹配。看到
但是我注意到如果包含xlabel
,情况就是这样。如果省略它,则勾号就可以了。看到
代码是
clear all; close all; clc; ntr = 'Interpreter'; ltx = 'latex'; cl = 'Color'; lw = 'LineWidth'; ls = 'LineStyle'; fs = 'FontSize';
figure;
subplot(2,1,1); a1 = gca;
ax1_pos = get(gca,'Position'); grid on; ylim([-80 40]); xlim([1e-2 1e3]);
set(gca,'TickLabelInterpreter',ltx);
xlabel('Frequency $\omega$ [rad/s]',ntr,ltx,fs,10);
a2 = axes('Position',ax1_pos,'Units','Normalized','YAxisLocation','Right','XAxisLocation','Top',cl,'none','XTick',[],'TickLabelInterpreter',ltx,...
'ytick',0:1/6:1,'yticklabel',{'$10^{-4}$','$10^{-3}$','$10^{-2}$','$10^{-1}$','$10^0$','$10^1$','$10^2$'});
linkaxes([a1 a2],'x');
subplot(2,1,2); a1 = gca;
ax1_pos = get(gca,'Position'); grid on; ylim([-2/3*pi 2/3*pi]); xlim([1e-2 1e3]);
xlabel('Frequency $\omega$ [rad/s]',ntr,ltx,fs,10);
set(gca,'ytick',[-2/3*pi:1/6*pi:2/3*pi]);
set(gca,'yticklabel',{'$-\frac{2}{3}\pi$','$-\frac{1}{2}\pi$','$-\frac{1}{3}\pi$','$-\frac{1}{6}\pi$','0','$\frac{1}{6}\pi$', ...
'$\frac{1}{3}\pi$','$\frac{1}{2}\pi$','$\frac{2}{3}\pi$'},'TickLabelInterpreter',ltx);
a2 = axes('Position',ax1_pos,'Units','Normalized','YAxisLocation','Right','XAxisLocation','Top',cl,'none','XTick',[],'TickLabelInterpreter',ltx,...
'ytick',0:1/8:1,'yticklabel',{'-120','-90','-60','-30','0','30','60','90','120'});
linkaxes([a1 a2],'x');
有人知道是什么原因造成的吗?