【问题标题】:How to use plotyy for 2 different plots inside a subplot?如何将 plotyy 用于子图中的 2 个不同的图?
【发布时间】:2015-06-07 21:42:16
【问题描述】:

我在子图中使用“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....

谁能帮帮我?

提前谢谢你!

【问题讨论】:

  • 如果它对您有帮助,请接受答案,如果它仍然不起作用,请发表评论,或者如果您以不同的方式解决问题,请发布您自己的解决方案作为答案。

标签: matlab plot axis subplot


【解决方案1】:

我无法告诉你为什么你的线路消失了,我运行的是 R2012b 版本,它也发生在我身上,所以它可能只是一个奇怪的错误。

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-01
    相关资源
    最近更新 更多