Using print function to save figures with text labels

조회 수: 5 (최근 30일)
Colin
Colin 2023년 9월 6일
댓글: Matt J 2023년 9월 8일
I have often saved multi-part figures using the print function, but recently labels added to these with the text function are no longer being saved in the final image (example below). I explored other options including exportgraphics and saveas, however none have the functionality of 'print'. The same disappearing-text issue is present independent of figure extension (.png, .pdf, etc.). What would be the best way to get the saved image, in this case testfigure.png, to look like the Matlab figure window?
figure(1);clf;
x=linspace(0,2*pi,10);plot(sin(x),'linewidth',2);
t=text(0.8,0.9,'my function','units','normalized'); %label appears in figure window
print('testfigure.png','-dpng','-r300');set(t,'fontweight','bold'); %label is missing in .png file
  댓글 수: 2
Catalytic
Catalytic 2023년 9월 6일
I explored other options including exportgraphics and saveas, however none have the functionality of 'print'.
The functionality you're struggling to find in other functions is critical information for us. Otherwise we can't know what to recommend. You can forget about getting print() to work the way you want. It's notoriously bad.
Colin
Colin 2023년 9월 6일
Yes, print() is definitely annoying but up until now has otherwise been working well enough for me in a few well-polished scripts. I guess the functionality I'm really hoping for is:
  • being able to set custom figure dimensions and resolutions
  • having the saved image match the figure window in terms of fonts, colors, subpanel placement, and added text
Sometimes in a pinch I've resorted to taking screenshots of the figure window, which hit all of these points except that their resolution is suboptimal (plus of course a programmatic solution is always better).

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2023년 9월 6일
편집: Matt J 2023년 9월 6일
  댓글 수: 11
Colin
Colin 2023년 9월 8일
편집: Colin 2023년 9월 8일
As described here
the current workaround solution with export_fig() is to only call text with 'units' as 'data' (which is the default) rather than 'units','normalized'. Then export_fig() will work exactly as expected.
Matt J
Matt J 2023년 9월 8일
Good! Hope Yair fixes it at some point.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by