Modifying second axes properties in plotyy
12 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
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
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')
See Also
Categories
Find more on Axis Labels 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!