サイズを変更してから PDF として印刷したい図があります。のようなものを使用して
set(hFig, 'PaperUnits', 'centimeters')
set(hFig, 'PaperSize', [x_B x_H]);
フィギュアのサイズを大幅に変更しない限り機能します。高さを減らすと、ある時点で xlabel が図の外に出ます。私はたくさん検索しましたが、基礎となる軸オブジェクトのサイズを手動で変更する解決策しか見つかりませんでした
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);
2 つの要素を手動で調整する必要があるため、このアプローチは好きではありません。
印刷する前に、すべてのテキストオブジェクトの「インタープリター」を「ラテックス」に設定しました(それが重要な場合)。印刷は
print(hFig, '-dpdf', '-loose', 'test.pdf');
「-loose」を使用してバウンディング ボックスを緩めたいと考えました。どんな助けでも大歓迎です!
編集: 実際にはインタープリター (none、tex、latex) がこれに関与しているようです。ここの投稿 (http://stackoverflow.com/questions/5150802/how-to-save-plot-into-pdf-without-large-margin-around) に触発され、この解決策を思いつきました:
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);