Reputation: 1848
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
.
Upvotes: 3
Views: 5070
Reputation: 12345
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.
Upvotes: 7