display rectangle on top of plotyy

3 ビュー (過去 30 日間)
Sebastian Roehn
Sebastian Roehn 2016 年 3 月 25 日
コメント済み: Mike Garrity 2016 年 3 月 25 日
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
uistack(h,'top')
uistack(hLine2,'down')
I really appreciate any help you can provide.
Greetings Sebastian

採用された回答

Mike Garrity
Mike Garrity 2016 年 3 月 25 日
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));
rectangle(axh(1),'Position',[1,0,20,3],'LineWidth',2)
is different from this:
[axh,hLine1,hLine2] = plotyy(1:100,randn(100,1),1:100,randn(100,1));
rectangle(axh(2),'Position',[1,0,20,3],'LineWidth',2)
  2 件のコメント
Sebastian Roehn
Sebastian Roehn 2016 年 3 月 25 日
Hello Mike,
thank you for your answer. But that isn't working, because you cannot specify an axes handle on a rectangle. You get this error:
Error using rectangle
Can't specify convenience arg for this object
Error in plotyy_rectangle (line 2)
h = rectangle(axh(2),'Position',[1,0,20,3],'LineWidth',2);
But your answer brought me to this solution:
hfig = figure(1);
[axh,hLine1,hLine2] = plotyy(1:100,randn(100,1),1:100,randn(100,1));
set(hfig,'CurrentAxes',axh(2))
h = rectangle('Position',[1,0,20,3],'LineWidth',2);
Greetings Sebastian
Mike Garrity
Mike Garrity 2016 年 3 月 25 日
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:
rectangle('Position',[1,0,20,3],'LineWidth',2,'Parent',axh(2))
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by