Problems printing graphics in pdf format

10 ビュー (過去 30 日間)
Lola Gadea
Lola Gadea 2024 年 11 月 10 日
コメント済み: Lola Gadea 2025 年 2 月 3 日
Since some time ago the graphs generated in matlab are saved empty in pdf format with the print function. This happens especially with the heatmap type
  6 件のコメント
Lola Gadea
Lola Gadea 2024 年 11 月 12 日
移動済み: Adam Danz 2024 年 11 月 12 日
no warning message appears. The graph is created well in Matlab but then in pdf it appears empty. If it saves well in png
Adam Danz
Adam Danz 2024 年 11 月 12 日
Please contact tech support and include instructions how to reproduce the problem. Feel free to include the URL of this thread. Also include your release information (R2024a).

サインインしてコメントする。

回答 (1 件)

Vedant Shah
Vedant Shah 2025 年 1 月 31 日
To save a heatmap or any other graph plotted using MATLAB in PDF format, we need to ensure that the figure's size and position properties match the on-screen appearance. To achieve this, you can refer to my following code:
% 10x10 matrix with random values between 0 and 1
data = rand(10, 10);
% Create the heatmap
h = heatmap(data)
h.Title = 'Dummy Heatmap';
h.XLabel = 'X-axis Label';
h.YLabel = 'Y-axis Label';
colormap('jet');
colorbar;
% saving the figure in PDF format
set(gcf,'Units','inches');
screenposition = get(gcf,'Position');
set(gcf,...
'PaperPosition',[0 0 screenposition(3:4)],...
'PaperSize',[screenposition(3:4)]);
print -dpdf -painters myHeatMap
The above code firstly creates a heatmap as usual. Then, I set the figure's size and position and create the PDF accordingly to ensure that the figure appears the same as it does on the screen.
The code for saving the figure works as follows: The first two lines measure the size of your figure (in inches). The next line configures the print paper size to fit the figure size. The last line uses the “print” command to export a vector PDF document as the output.
  1 件のコメント
Lola Gadea
Lola Gadea 2025 年 2 月 3 日
Very useful. Thank you very much.
Although I don't understand why this didn't happen with previous versions of Matlab.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

タグ

製品


リリース

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by