Change plotyy axis properties

조회 수: 5 (최근 30일)
Franco
Franco 2014년 10월 7일
댓글: Image Analyst 2014년 10월 7일
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.

답변 (3개)

Andrew Reibold
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
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!
Franco
Franco 2014년 10월 7일
This is what I mean. I need to change the font sizes for this figure.

댓글을 달려면 로그인하십시오.


Star Strider
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
Franco
Franco 2014년 10월 7일
Try it on this
Star Strider
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
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
Franco
Franco 2014년 10월 7일
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 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 CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by