3

I am using plotyy to plot two vectors on different y-axes. I wish to add a third vector to one of the two axes. Can someone please tell me why the following code is not working?

[ax h1 h2] = plotyy(1:10,10*rand(1,10),1:10,rand(1,10));
hold on; plot(ax(2),1:10,rand(1,10));
??? Error using ==> plot
Parent destroyed during line creation

I simply wish to add an additional vector to one of the axes (ax(1),ax(2)) created by plotyy.

1 Answer 1

7

Apply hold to the axis of interest.

[ax h1 h2] = plotyy(1:10,10*rand(1,10),1:10,rand(1,10));
hold(ax(2), 'on'); 
plot(ax(2),1:10,rand(1,10));

plotyy works by creating two axes, one on top of the other. You are carefully adding the new vector to the second axis. The hold property is also a per-axis property, so you just need to make sure that the hold is set on the same axis.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I did not realize hold was applied to individual axes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.