Modifying second axes properties in plotyy

2 views (last 30 days)
J
J on 28 Mar 2012
Commented: Aditya on 13 Mar 2015
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!

Answers (1)

Sean de Wolski
Sean de Wolski on 28 Mar 2012
[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 Comments
J
J on 28 Mar 2012
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 on 13 Mar 2015
Hi J,
As Sean mentioned use set(get(AX(2),'ylabel'), 'string', 'Secondlabel')
and not set(AX(2), 'ylabel', 'Secondlabel')

Sign in to comment.

Categories

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!