3

サイズを変更してから 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);
4

1 に答える 1

1

これで問題が完全に解決されるわけではありません (コードのクリーンアップに役立つだけかもしれません) が、ファイル交換のfigコードが役立つことがわかりました。これにより、余白に隣接することなく Figure の正確なサイズを簡単に設定できます。

于 2011-07-11T01:29:44.097 に答える