Change plotyy axis properties
5 views (last 30 days)
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.
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
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.
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);