plotyy
的第一个输出来获取和使用轴句柄,gca
只会修改其中一个轴。 - sco1plotyy
的第一个输出会给你那个组。 - sco1plot
调用中似乎不存在,所以这看起来像是由plotyy
创建轴对象的内部错误。作为一种替代方案,您可以将多个轴叠放在一起,从而利用“默认”的缩放行为(缺乏更好的单词)。这种方法还允许您完全独立地控制两个轴的行为,并避免plotyy
的许多缺陷。% Sample data
x = 1:10;
y1 = 1:2:20;
y2 = 1:0.5:5.5;
% Create axes & store handles
h.myfig = figure;
h.ax1 = axes('Parent', h.myfig, 'Box', 'off');
if ~verLessThan('MATLAB', '8.4')
% MATLAB R2014b and newer
h.ax2 = axes('Parent', h.myfig, 'Position', h.ax1.Position, 'Color', 'none', 'YAxisLocation', 'Right');
else
% MATLAB 2014a and older
ax1position = get(h.ax1, 'Position');
h.ax2 = axes('Parent', h.myfig, 'Position', ax1position, 'Color', 'none', 'YAxisLocation', 'Right');
end
% Preserve axes formatting
hold(h.ax1, 'on');
hold(h.ax2, 'on');
% Plot data
plot(h.ax1, x, y1, 'b');
plot(h.ax2, x, y2, 'g');
linkaxes([h.ax1, h.ax2], 'x');
以下是示例图片:
请注意,我只连接了 x
轴,但您可以使用 linkaxes
呼叫来连接 x
和 y
轴。
由于某种原因,plotyy默认将轴的“Ytickmode”设置为手动模式。
由于plotyy为两个数据集创建了2组坐标轴,因此为每个轴设置“Ytickmode”应该可以解决这个问题。
可以通过以下方式完成:
AX=plotyy(...) %this will create an axis with 2 elements one for each axis
AX(1).YTickMode='auto';
AX(2).YTickMode='auto';