Axes2FigPrint.m 649 B

1234567891011121314151617181920212223
  1. close all
  2. figure('units','pix','pos',[200 200 850 750])
  3. ax=axes;
  4. plot((1:10).^2)
  5. set(ax,'units','pix')
  6. legend('x^2')
  7. xlabel('X Label','fontsize',12)
  8. ylabel('Y Label','fontsize',12)
  9. title('Title','fontsize',24)
  10. drawnow
  11. % Now capture the axes and labels.
  12. P=get(ax,'pos');
  13. T=get(ax,'tightinset');
  14. h=[P(1)-T(1)-5 P(2)-T(2)-5 P(3)+P(1)/2+T(3)+15 P(4)+P(2)/2+T(4)+10];
  15. F=getframe(gcf,h);
  16. [X,Map]=frame2im(F);
  17. % I put the funny background color so the captured area stands out.
  18. figure('color',[.6 .2 .2],'units','pix','pos',[26 33 1184 925])
  19. image(X)
  20. set(gca,'visible','off')
  21. axis normal
  22. imwrite(X,'myimage.jpg') % save the image