首页 文章

Matlab多次打破yaxis

提问于
浏览
3

我试图通过使用breakyaxis多次打破yaxis . 正如链接的评论所示,其他人似乎也有多次打破y轴的问题 . 例如:

x = linspace(0,10,11);
y1 = 0.01*x;
y2 = -0.01*x + 5;
y3 = 0.05*x + 10;
plot(x,y1)
hold on
plot(x,y2)
plot(x,y3)
hold off

请注意,因为相对于等式中的常数,斜率非常小,所以将图形绘制在一起将产生3条平坦的线条 . 我想通过在y1和y2之间以及y2和y3之间断开yaxis来显示斜率 . 但是,如果我尝试:

x = linspace(0,10,11);
y1 = 0.01*x;
y2 = -0.01*x + 5;
y3 = 0.05*x + 10;
plot(x,y1)
hold on
plot(x,y2)
plot(x,y3)
breakyaxis([0.15 4.85])
breakyaxis([5.05 9.95])
hold off

我收到一条错误消息:“splitYLim必须在get(AX,'YLim')”给出的范围内 .

仅使用1个breakyaxis功能就可以完美运行 . 有没有办法可以打破我的yaxis两次?

注意:这只是一个用于解释我的问题的补充数据,我必须将它们全部绘制在1个图形中,因此拆分图形不是解决方案 . 我不介意使用其他功能,只要我可以打破我的yaxis两次 .

编辑:

我做了一些调试,错误信息来自breakyaxis第72-75行 . 以下是触发错误消息的代码:

mainYLim = get(mainAxes,'YLim');
if (any(splitYLim >= mainYLim(2)) || any(splitYLim <= mainYLim(1)))
   error('splitYLim must be in the range given by get(AX,''YLim'')');
end

在第一个breakyaxis中,mainYLim设置为[0,12],splitYLim设置为我指定的范围:[0.15,4.85] .

但是,在第二个breakyaxis中,mainYLim设置为[0,1],splitYLim([5.05,9.9])超出mainYLim的范围 .

请注意,mainAxes在代码中早先定义为 mainAxes = gca .

因此,问题在于,在第二个breakyaxis中,mainYLim报告的范围比我的情节需要的范围小得多 . 我该如何解决?

1 回答

  • 0

    我相信你应该使用标准化来相对显示斜率 .

    x = linspace(0,10,11);
    y1 = 0.01*x;
    y2 = -0.01*x + 5;
    y3 = 0.05*x + 10;
    plot(x,y1/norm(y1))
    hold on
    plot(x,y2/norm(y2))
    plot(x,y3/norm(y3))
    % breakyaxis([0.15 4.85])
    % breakyaxis([5.05 9.95])
    hold off
    legend('y1','y2','y3')
    

    enter image description here

相关问题