3

I'm trying to break yaxis multiple times by using breakyaxis. As seen in the comments of the link, other people also seem to have the issue of breaking the y-axis multiple times. For example:

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

Note that because the slope is so small relative the the constant in the equation, plotting the graphs together will result in 3 flat looking lines. I want to show the slope by breaking yaxis twice in between y1 and y2, and y2 and y3. However if I try:

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

I get an error message saying: "splitYLim must be in the range given by get(AX,'YLim')".

Using just 1 breakyaxis function works perfectly. Is there a way that I can break my yaxis twice?

Note: This is just a made-up data to explain my problem, and I have to plot them all in 1 graph, so splitting the graph is not the solution. I don't mind using other functions, as long as I can break my yaxis twice.

EDIT:

I did a little more of debugging, and the error message is coming from line 72-75 in breakyaxis. Here is the codes that triggers the error message:

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

In the first breakyaxis, mainYLim is set to [0,12], and splitYLim is set to the range that I specify: [0.15, 4.85].

However, in the second breakyaxis, mainYLim is set to [0,1], and splitYLim ([5.05, 9.95]) is outside the range of mainYLim.

Note that mainAxes is defined earlier in the code as mainAxes = gca.

The problem, thus, is due to the fact that in second breakyaxis, mainYLim is reporting a range much smaller than what my plot needs. How can I fix it?

Hosea
  • 205
  • 1
  • 6
  • What do you get if you type `get (ax,'ylim')` after the first `braekyaxis`? – Adiel Jan 31 '18 at 22:03
  • You can also use small y values and intervals so you can see the slopes, and after ploting just change `yticklabels` – Adiel Jan 31 '18 at 22:06
  • @Adiel if I type `get (ax,'ylim')`, I get that ax is undefined variable. See my edit for more details on the problem. – Hosea Feb 01 '18 at 14:54
  • Because you did not define it like in the edit that you just added. Maybe try in the second command to give input of [0.505 0.995], because after one call the ylim transfrered to be [0 1]. You need keep debugging it, and some trial and error if you don't know to read the code there – Adiel Feb 01 '18 at 21:44

1 Answers1

0

I believe you should use normalization to display the slope relatively.

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

Mohammad nagdawi
  • 553
  • 4
  • 18
  • 1
    While your solution may be good in certain cases, interpreting the graph after normalization for my case is tricky and not recommended. I specifically want to break my yaxis twice for my data visualization. – Hosea Feb 01 '18 at 14:57
  • Can I know why? – Mohammad nagdawi Feb 02 '18 at 16:04