Change plotyy axis properties

5 views (last 30 days)
Franco
Franco on 7 Oct 2014
Commented: Image Analyst on 7 Oct 2014
I have a .fig file that was generated from using the plotyy function. I now have to change the tick marks and the label font sizes, but every time I use the get(gca...) function, It only gets one of the plots and not the other. Anyone out there know a solution to my problem? Thanks in advance.

Answers (3)

Andrew Reibold
Andrew Reibold on 7 Oct 2014
Click the plot that you want to change first.
gca selects the most recently 'active' one. Clicking one will make it the 'active' one
  3 Comments
Andrew Reibold
Andrew Reibold on 7 Oct 2014
Edited: Andrew Reibold on 7 Oct 2014
I suggest using the mouse xD
You can also set it to a 'handle' if thats the correct term.
do like
hh=plot(....)
then instead of gca try
set(hh, ...)
So what is it, is it two plots on one axes? I'm not sure I fully understand the issue also.
Also, if you click the 'arrow' mouse cursor thing in the figure menu, then double click on lines, tick marks, etc, you can change lots of properties!
Franco
Franco on 7 Oct 2014
This is what I mean. I need to change the font sizes for this figure.

Sign in to comment.


Star Strider
Star Strider on 7 Oct 2014
Edited: Star Strider on 7 Oct 2014
This will get you both sets of y-variables:
hd = get(gcf, 'Children');
yd1 = get(get(hd(1), 'Children'), 'YData'); % ‘Right’ 'YData'
yd2 = get(get(hd(2), 'Children'), 'YData'); % ‘Left’ 'YData'
ytl1 = get(hd(1), 'YTickLabel'); % ‘Right’ 'YTickLabel'
ytl2 = get(hd(2), 'YTickLabel'); % ‘Left’ 'YTickLabel'
To change the 'YTick', 'YTickLabel' values and properties, replace get with set.
  2 Comments
Star Strider
Star Strider on 7 Oct 2014
I was actually able to get this code to work with ‘PropFig27.fig’ but I had to restart my MATLAB session to do it. (I had attempted to do something else with it to get some other values and somehow screwed up the ‘hg’ properties. Fixed now.)
This worked:
openfig('PropFig27.fig')
hd = get(gcf, 'Children');
ytl1 = get(hd(2), 'YTickLabel'); % ‘Right’ 'YTickLabel'
ytl2 = get(hd(3), 'YTickLabel'); % ‘Left’ 'YTickLabel'
and produced (temporarily removing the semicolons):
ytl1 =
80
82.2222
84.4444
86.6667
88.8889
91.1111
93.3333
95.5556
97.7778
100
ytl2 =
0
111
222
333
444
555
666
777
888
1000
You should be able to do similar commands with set to change them.

Sign in to comment.


Image Analyst
Image Analyst on 7 Oct 2014
You can get both handles at once when you call plotyy. Then just set the font of whatever you want:
workspace; % Make sure workspace panel is showing.
x = 1 : 10;
y1 = 1:10
y2 = 3:12;
bothHandles = plotyy(x, y1, x, y2) % Get both handles in one call.
% Set font on the left y axis.
set(bothHandles(1), 'FontSize', 8);
% Set font on the right y axis.
set(bothHandles(2), 'FontSize', 25);
  2 Comments
Franco
Franco on 7 Oct 2014
That only works when you are making the figure. I already have the figure file an dI need to change the font sizes.
Image Analyst
Image Analyst on 7 Oct 2014
Yes and that is the most efficient place to set the font - when you are creating the figure, not after the fact when you have lost information on it and have to do some code gymnastics to recover it.

Sign in to comment.

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!