Exporting large figure on headless servers

4 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by