Missing part of my figure when saving as pdf
126 ビュー (過去 30 日間)
古いコメントを表示
Jaime De La Mota Sanchis
2022 年 4 月 30 日
コメント済み: Jaime De La Mota Sanchis
2022 年 5 月 2 日
Some time ago I made a post in whichI asked for a better optimization of the space when saving a figure.
My code now looks as follow:
figure ('Position',[0 0 1200 400]);
subplot(1,2,1)
contourf(Y,X, mediaU3D)
hold on
axesm mercator;
plot(coastlon,coastlat,'k', 'LineWidth', 1.5)
axis([-20 -10 23 32])
c2 = colorbar;
xlabel('Longitude(^o)')
ylabel('Latitude(^o)')
title('X-direction')
subplot(1,2,2)
contourf(Y,X, mediaV3D)
hold on
axesm mercator;
plot(coastlon,coastlat,'k', 'LineWidth', 1.5)
axis([-20 -10 23 32])
c2 = colorbar;
xlabel('Longitude(^o)')
ylabel('Latitude(^o)')
title('Y-direction')
sgtitle('Mean wind velocity (m/s) realizations')
However, when I try to save the figure manually by pressing the save button, see figure1
and try to save it as a pdf. Then, unfortunately I get the result that can be seen in the attached .pdf file, the colorbar of the right subfigure is missing.
Can someone please tell me what am I doing wrong?
Best regards.
Jaime.
2 件のコメント
Riccardo Scorretti
2022 年 4 月 30 日
編集済み: Riccardo Scorretti
2022 年 4 月 30 日
Can you post also the variables required to execute the code, so we can play with it? I'm unable to reproduce with randomly generated data.
That's being said, this problem could be linked with paper orientation. Perhaps you could try this before saving the image:
fig = gcf ; fig.PaperOrientation = 'landscape';
採用された回答
Richard Quist
2022 年 5 月 1 日
編集済み: Richard Quist
2022 年 5 月 1 日
When using File -> Save As, MATLAB saves the figure to a "page" when saving the figure to PDF. As the warning mentions, your figure is too wide for the page size, which is why it is being cut off. There are a couple of approaches you can take to get around this issue.
- If you are using R2020a or later, you can use the exportgraphics command from the MATLAB command line to produce a tightly cropped PDF. See below for an example of how to do this.
- Before saving the figure you can set the figure's PaperSize to match the figure's Position, so that the PDF page size will be large enough to hold the entire content. See below for an example of how to do this.
Example using exportgraphics:
% This example assumes that 'fig' is the handle to your figure.
% In R2020a and later, you can use the exportgraphics command and specify
% the 'ContentType' as 'vector' (to ensure tightly cropped, scalable output):
exportgraphics(fig, 'output.pdf', 'ContentType', 'vector');
Example setting the figure's PaperSize before saving the figure:
% This example assumes that 'fig' is the handle to your figure.
% The figure's PaperSize property controls the page size for PDF output
% set the figure Units to match the PaperUnits, but first, save the
% figure's Units value so we can restore it when done
origUnits = fig.Units;
fig.Units = fig.PaperUnits;
% set the Page Size (figure's PaperSize) to match the figure size in the Paper units
fig.PaperSize = fig.Position(3:4);
% restore the original figure Units
fig.Units = origUnits;
% Now, when you save the figure it should not be cut off.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Printing and Saving についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!