Saving figure as a image
조회 수: 22 (최근 30일)
이전 댓글 표시
I am saving my output figures as images. But when I run my matlab script from different computers, the figures look different. As in the labels and legends are different sizes, etc. I want the image outputs to be exactly the same no matter what computer I run it on, I do not want to have computer specific scripts.
I am not a graphics person, so I do not know what causes this. Whether it is the screen resolution, renderer, file type, options or what? I do not know where to start.
The code I am using to save figure is:
output_file = 'example_image.png'
saveas(figure1,fullfile(folderName, output_file));
which outputs the following image:
Help!!
댓글 수: 9
Adam Danz
2021년 4월 13일
From the figure menu, when I select File > SaveAs > PDF the results look quite similar.
채택된 답변
Adam Danz
2021년 4월 13일
Comparing the two png files in one of your previous comments shows an upper y axis in one figure that doesn't exist in the second figure. This is more than a version difference. The only why that would be possible is if the two systems are using different versions of the code or if the system using the older Matlab release is quitting early due to an error.
There is also a difference in fontsize. That can be fixed by explicitly setting the fontsizes in your code. The difference in figure size can be controlled by explicitly setting figure size.
댓글 수: 10
Adam Danz
2021년 4월 13일
Regarding the inconsistent figure sizes, there are many areas to troubleshoot and I've found that exportgraphics does some unexpected things with figure size. For example in this example from the documentation, the printed fig should be "approximately 3 inches" but it's much larger when i try it (r2021a).
The export_fig function on the file exchange will likely work for you:
추가 답변 (1개)
David Hill
2021년 4월 1일
You might try figure2pdf in file exchange.
댓글 수: 2
Adam Danz
2021년 4월 13일
meghannmarie's answer moved here as a comment
-----------------------------------------------------------------------------
The figure2pdf function does not work. The pictures still save differently on different machines.
Look at my attachments, one is saved on my laptop and one is saved on our hpc. They are different, but same exact script. I think it is something to do with resolution of screen, but how do I get around it?
참고 항목
카테고리
Help Center 및 File Exchange에서 Printing and Saving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!