Note that there are some explanatory texts on larger screens.

plurals
  1. POMATLAB: Resizing a figure properly
    primarykey
    data
    text
    <p>I have a figure that I would like to resize and afterwards print as a PDF. Using something like</p> <pre><code>set(hFig, 'PaperUnits', 'centimeters') set(hFig, 'PaperSize', [x_B x_H]); </code></pre> <p>works as long as I do not resize the figure too drastically. If I reduce the height then at some points the xlabel moves out of the figure. I have searched a lot but only found an solution to manually resize the underlying axes-object</p> <pre><code>scalefactor = 0.96; movefactor = 0.82; hAx = get(gcf,'CurrentAxes'); g = get(hAx,'Position'); % 1=left, 2=bottom, 3=width, 4=height g(2) = g(2) + (1-movefactor)/2*g(4); g(4) = scalefactor*g(4); set(hAx,'Position',g); </code></pre> <p>I do not like this approach since I have to manually adjust the two factors.</p> <p>Before printing I set the 'interpreter' to 'latex' of all text-objects (if that is of concern). Printing is achieved using</p> <pre><code>print(hFig, '-dpdf', '-loose', 'test.pdf'); </code></pre> <p>I hoped to loosen the bounding box by using '-loose'. Any help is highly appreciated!</p> <p>edit: It seems that really the interpreter (none, tex, latex) plays a role in this. I got inspired by this post here (http://stackoverflow.com/questions/5150802/how-to-save-plot-into-pdf-without-large-margin-around) and came up with this solution:</p> <pre><code>tightInset = get(gca, 'TightInset'); position(1) = tightInset(1); position(3) = 1 - tightInset(1) - tightInset(3); if strcmpi(x_Interpreter,'latex') position(2) = tightInset(2)+ 1*tightInset(4); position(4) = 1 - tightInset(2) - 2*tightInset(4); else position(2) = tightInset(2)+ 0*tightInset(4); position(4) = 1 - tightInset(2) - 1*tightInset(4); end set(gca, 'Position', position); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload