Change size of plotyy figure before saving.
2 views (last 30 days)
Show older comments
Brian
on 21 Oct 2014
Commented: Michael Haderlein
on 21 Oct 2014
Hi, I would like to change the size of a "plotyy" plot and save it as a eps file. Having the following figure:
h = figure(1)
[ax,p1,p2] = plotyy(aElem,z1,aElem,z2,'plot');
set(p1,'LineStyle','*','Color','k');
set(p2,'LineStyle','o','Color','k');
set(ax,{'yColor'},{'k';'k'})
set(ax,'xColor','k')
grid on
xl = xlabel(ax(2),'Crack length [mm]');
I would like to reduce the figure size before saving. The challenge for me is to do it without cutting off some of the x label text. I usually do the following for normal plots with "plot":
figWidth = 10.0; %cm
figHeight = 7.2; %cm
pixelsCm = 1680/47.5; % pixels per cm on my computer
set(gca, 'Units', 'centimeters'); % axes definitions are in cm
lpos = get(gca, 'OuterPosition'); % Gets outer position of the axes
set(gca, 'OuterPosition', [lpos(1)-0.2 lpos(2)-0.2 figWidth-1 figHeight]); % Reduce margins. [left bottom width height] are normalized to [0, 1]. Use negative values for left and bottom to trim off left/bottom margins.
set(gcf, 'PaperPositionMode', 'manual'); % Lets you setup figure size manually so that 'PaperPosition' defines size of exported grapics.
set(gcf, 'Units', 'pixels', 'Position',[10*pixelsCm 10*pixelsCm figWidth*pixelsCm figHeight*pixelsCm]); % position on screen and size of figure. The pixelsCm lets you print out in the true size on screen.
set(gcf, 'Units', 'centimeters','PaperPosition', [1 1 figWidth figHeight]); % Sets the size of the figure for the saved eps file.
and then save the figure with:
saveas(h,'figurename.eps', 'psc2')
But this only changes one of the axes. Does anyone know how to change both the same?
Thanks in advance.
Regards Brian
0 Comments
Accepted Answer
Michael Haderlein
on 21 Oct 2014
Edited: Michael Haderlein
on 21 Oct 2014
You need the handles of both axes. You already use these handles as first output argument of plotyy in a variable you call ax:
[ax,p1,p2] = plotyy(aElem,z1,aElem,z2,'plot');
...
set(ax,{'yColor'},{'k';'k'})
So, later in your code, you should simply use ax instead of gca and that's it.
Edit:
In this line:
lpos = get(gca, 'OuterPosition');
you might want to keep gca or use ax(1). Otherwise you'll get a cell and things get complicated with no need.
3 Comments
More Answers (0)
See Also
Categories
Find more on Two y-axis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!