Exporting large figure on headless servers

8 ビュー (過去 30 日間)
Yi-xiao Liu
Yi-xiao Liu 2022 年 7 月 13 日
回答済み: Brahmadev 2023 年 9 月 8 日
I am trying to export some large figures (~1e4 by 1e4 surf plots) into bitmap images directly on our HPC cluster. Here is some test script I generated:
n=1e3;
[X,Y,Z] = peaks(n);
fig=figure('visible', 'off');
surf(X,Y,Z,...
"EdgeColor","none","FaceColor","flat")
exportgraphics(fig,"Z.png",'Resolution',1200)
colorbar
caxis([0,10])
daspect([1,1,1e-2])
axis tight
title(append("$\bar{t}=",num2str(0,"%.3f"),"$"),"Interpreter","latex")
fig.CurrentAxes.FontSize=16;
fig.Position = [0,0,6,6];
fig.Units = 'inches';
exportgraphics(fig,"Zm.png",'Resolution',1200)
print(fig,"Zp.png",'-dpng','-r1200')
close(fig)
imshow(imread("Z.png"))
imshow(imread("Zm.png"))
imshow(imread("Zp.png"))
MATLAB was started with -nodisplay -nodesktop -nosplash options.
The problem is that when n is large enough (~1e4) the exporter seems to hang there forever, without any noticable consumption in CPU or RAM. Even for smaller n, the exported images are of crappy resolution, despite I specify a 1200 DPI, as you can view above. I have also attached the output generated on our HPC cluster. Is there anything I can do?

回答 (1 件)

Brahmadev
Brahmadev 2023 年 9 月 8 日
Hi Yi-xiao,
I understand that you are trying to plot large surf plots and export them using the "exportgraphics" function.
The following code that sets the aspect ratio and position might be the cause for the blank output:
daspect([1,1,1e-2])
fig.Position = [0,0,6,6];
This stretches the figure to a 100:1 ratio and makes it 6x6 pixels.
For your use case, setting the "resolution" attribute to 1200 is exporting images with significantly better resolution compared to default in MATLAB R2023a.
Hope this helps!

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by