如何将 plotyy 用于子图中的 2 个不同图?

How to use plotyy for 2 different plots inside a subplot?

我在子图中使用 'plotyy' 时遇到了一些问题。

我想要一个有 4 个数字的子图并在每个数字中使用 'plotyy'。由于轴的缩放比例,我遇到了一些问题,现在我已经为第一个图形解决了这个问题,但是当我尝试对子图中的第二个图形使用相同的结构时,第二个图形是完美的,但第一个一个变成只有一个图而不是前两个图的图(因此,第一个 'plotyy' 停止工作)。 为了更好地理解我的问题,我使用的代码是:

AXInv = subplot(2,2,1);  % Auto-fitted to the figure.
PInv = get(AXInv,'pos');    % Get the position.
delete(AXInv)
[AXInv,H1,H2] = plotyy(h,Inv,h,prod_Inv,'plot');
set(AXInv,'pos',PInv)       % Recover the position.

line([0 24],[0 1],'parent',AXInv(1),'Color',[1 1 1]) % Axis is not scaled
axis auto % Numbers on axes are crushing.
set(AXInv(1),'ytickmode','auto')  % This is new....
line([0 24],[0 1500],'parent',AXInv(2),'Color',[1 1 1]) % Axis is not scaled
axis auto % Numbers on axes are crushing.
set(AXInv(2),'ytickmode','auto')  % This is new....


AXPrim = subplot(2,2,2);  % Auto-fitted to the figure.
PPrim = get(AXPrim,'pos');    % Get the position.
delete(AXPrim)
[AXPrim,H1,H2] = plotyy(h,Prim,h,prod_Prim,'plot');
set(AXPrim,'pos',PPrim)       % Recover the position.

line([0 24],[0 1],'parent',AXPrim(1),'Color',[1 1 1]) % Axis is not scaled
axis auto % Numbers on axes are crushing.
set(AXPrim(1),'ytickmode','auto')  % This is new....
line([0 24],[0 1500],'parent',AXPrim(2),'Color',[1 1 1]) % Axis is not scaled
axis auto % Numbers on axes are crushing.
set(AXPrim(2),'ytickmode','auto')  % This is new....

谁能帮帮我?

提前致谢!

我不能告诉你为什么你的行消失了,我是 运行 版本 R2012b 我也遇到过,所以它可能只是一个奇怪的错误。

但是,要解决此问题,您可以删除两个 delete 语句,因为它们在这里没有任何实际用途。如果没有这些,您将获得正确的 plotyy-plot(具有虚拟值):

如果右轴上的双勾打扰了您,您可能想看看 File Exchange's plt 来解决这个问题。

下次的一条建议:尝试包含一个最小的代码工作示例,这样人们就不必自己用数据填充变量。您可能会更快得到答复。 ;)