Saving a .fig file as a .png

조회 수: 30 (최근 30일)
Edward Steen
Edward Steen 2017년 6월 30일
댓글: Jan 2017년 6월 30일
I'm trying to save .fig files as .png in order to include them in a Latex document. The plots look great in .fig format, but when I save them as .png files, the font sizes that I specified don't stick and the font sizes revert to something much smaller than I want. Is there a way to get around this. I would use the .fig files, but Latex doesn't seem to like this format. Thanks for any help.

채택된 답변

Jan
Jan 2017년 6월 30일
You forgot to mention how you create the PNG file. With a screenshot the output equals the display on the screen exactly:
F = getframe(gcf);
imwrite(F.cdata, 'YouFile.png')
  댓글 수: 2
Edward Steen
Edward Steen 2017년 6월 30일
Here is my code creating the .fig file:
figure(1) subplot(2,1,1) x2=aa(:,1); y2=aa(:,2); z2=aa(:,3); plot(x2,y2)
dx=0.1; dy=0.1; x_edge=floor(min(x2)):dx:ceil(max(x2)) y_edge=floor(min(y2)):dy:ceil(max(y2))
[X2,Y2]=meshgrid(x_edge,y_edge); Z2=griddata(x2,y2,z2,X2,Y2); contourf(X2,Y2,Z2,30) %or contourf with 50 lines title('Stability Contours of \lambda_1','fontsize',16) xlabel('\alpha_3','fontsize',18) ylabel('\alpha_4','fontsize',18) colorbar
Then what??
Thanks, and I appreciate the help.
Jan
Jan 2017년 6월 30일
The code to create the figure does not matter. The code I've posted creates a screen copy of every figure. Did you try to run it?
Using gcf is less safe than defining the figure handle explicitely:
FigH = figure;
... your code
drawnow;
F = getframe(FigH);
imwrite(F.cdata, 'YouFile.png')
gcf can reply an unexpected figure, if the user clicks on another figure during the code runs.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by