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?
댓글 수: 0
답변 (1개)
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!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!