如上所述,我想放大使用plotyy
创建的图表。
执行此操作时,yTicks
不会更新为可见的新限制。
因此,如果你放大太多,你可能会发现你没有看到任何yTicks
。
我找到了ActionPostCallback
函数,但我没有得到它,xTicks
很好。
代码:
figure, plotyy(1:10,1:2:20,1:10,1:0.5:5.5)
结果:
答案 0 :(得分:4)
您可能希望将YTickMode
属性设置为auto
。
h = plotyy(1:10,1:2:20,1:10,1:0.5:5.5)
set(h, 'YTickMode','Auto')
完整代码:
figure
subplot(121)
h1 = plotyy(1:10,1:2:20,1:10,1:0.5:5.5)
title('Original')
subplot(122)
h2 = plotyy(1:10,1:2:20,1:10,1:0.5:5.5)
title('Zoom')
set(h2, 'YTickMode','Auto')
答案 1 :(得分:3)
因为“正常”plot
调用中似乎不存在此行为,所以这看起来像plotyy
创建轴对象的内部错误。作为一种替代方案,您可以将多个轴堆叠在一起,因此可以使用“默认”(缺少更好的单词)缩放行为。这种方法还允许您独立地完全控制两个轴的行为,并避免看似很多plotyy
的弱点。
我稍微调整one of my previous answers作为这种情况的一个例子。
% 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
个轴。
答案 2 :(得分:2)
出于某种原因,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';