display rectangle on top of plotyy

2 views (last 30 days)
Hello community,
I would like to draw a rectangle on top of a plotyy. But the second plot data are always on top of the rectangle. I tried it with uistack, but that isn't working. Here is a small example...
[axh,hLine1,hLine2] = plotyy(1:100,randn(100,1),1:100,randn(100,1));
h = rectangle('Position',[1,0,20,3],'LineWidth',2);
% rectangle on top
I really appreciate any help you can provide.
Greetings Sebastian

Accepted Answer

Mike Garrity
Mike Garrity on 25 Mar 2016
The first return value from plotyy (axh in your case) is an array of two handles. Try putting the rectangle in the other one. In other words, this:
[axh,hLine1,hLine2] = plotyy(1:100,randn(100,1),1:100,randn(100,1));
is different from this:
[axh,hLine1,hLine2] = plotyy(1:100,randn(100,1),1:100,randn(100,1));
Mike Garrity
Mike Garrity on 25 Mar 2016
Sorry, I think that the 1st arg for rectangle was added in R2016a. It's just shorthand for a form that's been around for a long time:
Most of the graphics objects take that first arg form. We've recently been going through and adding it to the ones which didn't have it.

Sign in to comment.

More Answers (0)


Find more on Two y-axis in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by