下面是我曾经在 MATLAB 图中对两个 y 轴具有相同比例的代码:
%% Additions by Dev-iL:
date = 1:10;
z = 4*randn(3,10);
spread = 0.2*sum(z,1);
figure();
%% Original code by RSerrano:
ax(2) = subplot(2,1,2);
% z = horzcat(zscore,signal1,signal2); % Dev-iL
yyaxis left
plot(date,z,'LineWidth',0.5);
ylabel('Z-score(residuals)');
set(ax(2),'YColor',[0 0 0],'YDir','normal');
ax(2).YLimMode = 'manual';
ax(2).YLim = [-8 8];
ax(2).YTickMode = 'manual';
ax(2).YTick = -8:2:8;
co1 = get(gca,'ColorOrder');
% Change to new colors.
set(gca, 'ColorOrder', [0.83 0.82 0.78; 0 0.5 0; 0.47 0.67 0.19],...
'NextPlot', 'replacechildren');
co1 = get(gca,'ColorOrder');
plot(date,z,'LineWidth',0.3);
z2 = spread;
yyaxis right
plot(date,z2,'Color',[0.31 0.31 0.31], 'LineWidth',0.5);
xlabel('Date');
ylabel('Spread(USD)');
title(['Spread and Trade Signals']);
legend('Z-score','Signal1', ...
'Signal2','Spread', ...
'Location','NE');
set(ax(2),'YColor',[0 0 0],'YDir','normal');
ax(2).YTick = -8:2:8;
axis tight
grid on
这导致:
如何使左 y 轴的ylim
和ytick
与右 y 轴相同?或者我如何将左 y 轴的ylim
and应用于ytick
右 y 轴?