Problems printing graphics in pdf format
이전 댓글 표시
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
What if anything changed (about your MATLAB code, about your MATLAB installation, about your computer, etc.) between the last time the graphs you exported were exported successfully and the first time they were exported empty?
What release of MATLAB are you using and what operating system?
Can you show a small (no more than a dozen lines or so) that generate an empty PDF when you export? Including the call to print will let us make sure you're using it in a way that is expected to work on your release.
Can you make sure you haven't overloaded the print function? What does this command show?
which -all print
Lola Gadea
2024년 11월 10일
이동: DGM
2024년 11월 10일
Walter Roberson
2024년 11월 10일
Better would be
fig = figure(ifig);
ax = gca(fig);
heatmap(ax, M_matrix_up,[],[],[],'TickAngle', 45, 'Colorbar',true,'Colormap', 'jet',...
'MinColorValue', min(min(TRATIO)), 'MaxColorValue', max(max(TRATIO)));
set(ax,'YTick',1:m);
set(ax,'XTick',1:m);
set(ax,'XTickLabel',states,'Fontsize',10);
set(ax,'YTickLabel',states,'Fontsize',10);
title(ax, strcat('Map of Warming Dominance for the',{' '},char(quantiles(j))))
set(fig, 'PaperSize',[29.7 21.0], 'PaperPosition',[0 0 29.7 21.0])
print(fig, strcat('Heat_map_US_',char(quantiles(j)),'_1950_2021'),'-dpdf')
print(fig, strcat('Heat_map_US_',char(quantiles(j)),'_1950_2021'),'-dpng')
print(fig, strcat('Heat_map_US_',char(quantiles(j)),'_1950_2021'),'-deps')
Under the assumption that ifig is a figure number or figure handle instead of a figure name, this could be,
figure(ifig);
ax = gca(ifig);
heatmap(ax, M_matrix_up,[],[],[],'TickAngle', 45, 'Colorbar',true,'Colormap', 'jet',...
'MinColorValue', min(min(TRATIO)), 'MaxColorValue', max(max(TRATIO)));
set(ax,'YTick',1:m);
set(ax,'XTick',1:m);
set(ax,'XTickLabel',states,'Fontsize',10);
set(ax,'YTickLabel',states,'Fontsize',10);
title(ax, strcat('Map of Warming Dominance for the',{' '},char(quantiles(j))))
set(ifig, 'PaperSize',[29.7 21.0], 'PaperPosition',[0 0 29.7 21.0])
print(ifig, strcat('Heat_map_US_',char(quantiles(j)),'_1950_2021'),'-dpdf')
print(ifig, strcat('Heat_map_US_',char(quantiles(j)),'_1950_2021'),'-dpng')
print(ifig, strcat('Heat_map_US_',char(quantiles(j)),'_1950_2021'),'-deps')
Adam Danz
2024년 11월 11일
Is there a warning message that appears when print() is not behaving expectedly?
Lola Gadea
2024년 11월 12일
이동: Adam Danz
2024년 11월 12일
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
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.
카테고리
도움말 센터 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!