How do I keep labels for "plotyy" with large font-sizes inside the figure?

3 views (last 30 days)
When I generate a figure with "plotyy" and set the font size of the axis and/or tick labels to a sufficiently large number, the labels are cut off by the edges of the figure. How can I fix this?  To reproduce, execute:
 
fontsize = 34;
x = linspace(0, 1);
y1 = x;
y2 = x.^2;
ax = plotyy(x, y1, x, y2);
set(ax(1),'Fontsize',fontsize);
set(ax(2),'Fontsize',fontsize);

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 12 Nov 2015
This issue is caused by a limitation of the "plotyy" function. A workaround is to set the 'OuterPosition' property of the first axis.
To do this for arbitrary label font sizes, add the following lines after all changes to fonts and labels:
 
outerPositionDifference = get(ax(2), 'OuterPosition') - get(ax(1), 'OuterPosition');
rightEdgeShift = outerPositionDifference(1) + outerPositionDifference(3);
set(ax(1), 'OuterPosition', [0, 0, 1-rightEdgeShift, 1]);
You can also set 'OuterPosition' manually if you want to further adjust the size of the axes.

More Answers (0)

Categories

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

Products


Release

R2015b

Community Treasure Hunt

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

Start Hunting!