Modifying second axes properties in plotyy

12 ビュー (過去 30 日間)
J
J 2012 年 3 月 28 日
コメント済み: Aditya 2015 年 3 月 13 日
Hi,
I've created a gui, and one of the "axes" is derived from a plotyy graph.
I would like to add labels to all of the axes. I can label the X axis and the Y axis on the left. I am having trouble adjusting any properties of the right hand side Y axis.
I can call [AX,H1,H2] = plotyy(etc) and I get AX giving the handle of my axes. However, if I use AX(2), I get an error about it not being a handle. There were a couple of other things which I tried (but rather embarrassingly, I can't remember them!).
If anyone has any suggestions, they'd be much appreciated!
Many thanks!

回答 (1 件)

Sean de Wolski
Sean de Wolski 2012 年 3 月 28 日
[ax h1 h2] = plotyy(1:10,'r',10:-1:1,'b')
ax(2)
works for me... Please post a full example that demonstrates the behavior you are seeing.
MORE per Comments
x1 = 1:10;
x2 = x1;
y1 = 1:10;
y2 = 10:-1:1;
[AX, ~, ~] = plotyy(x1, y1, x2, y2, 'semilogx');
set(gca, 'yminorgrid', 'on')
set(gca, 'yminortick','on')
ylabel('Yaxis')
set(get(AX(2),'ylabel'), 'string', 'Secondlabel')
If you look at:
get(AX(2))
'ylabel' is a handle to a text object. That is why you are seeing that error message. You need to set the string of the object corresponding to that handle (this is what I did above).
Of course, for this application, you could just call ylabel() with the axes_handle:
ylabel(AX(2),'hello world')
  2 件のコメント
J
J 2012 年 3 月 28 日
Hi Sean,
Thanks for your reply.
So I call [AX, ~, ~] = plotyy(x1, y1, x2, y2, 'semilogx') and then I set the left hand variables as follows:
set(gca, 'yminorgrid', 'on')
set(gca, 'yminortick','on')
ylabel('Yaxis')
then if I try to do set(AX(2), 'ylabel', 'Secondlabel'). The error message is: Error using set
Value must be a handle but just before then, the window prints that AX =
10.0155 12.0156
Many thanks!
Aditya
Aditya 2015 年 3 月 13 日
Hi J,
As Sean mentioned use set(get(AX(2),'ylabel'), 'string', 'Secondlabel')
and not set(AX(2), 'ylabel', 'Secondlabel')

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

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by