Change plotyy axis properties
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(3 个)
Andrew Reibold
2014-10-7
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 个评论
Andrew Reibold
2014-10-7
编辑:Andrew Reibold
2014-10-7
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!
Star Strider
2014-10-7
编辑:Star Strider
2014-10-7
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 个评论
Star Strider
2014-10-7
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.
Image Analyst
2014-10-7
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 个评论
Image Analyst
2014-10-7
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Two y-axis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!