How can I print only the axes of my figure?
5 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Commented: darova
on 16 May 2020
I am trying to write just the contents of the axes in my figure to an image file for use in another application.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
This can be done using the GETFRAME and IMWRITE functions, as illustrated in the following example.
Although this technique may be most useful when working with images, this example will plot a simple line and a legend to illustrate the fact that this technique is a true screen capture of the axes.
1. Create the following line and insert a legend in the plot.
plot(1:10)
legend('text')
2. Now grab the contents of the current axes using GETFRAME
f=getframe(gca)
The structure, f, contains two fields: "cdata", and "colormap". In this case, "colormap" is empty because "cdata" is not an indexed image.
3. Use IMWRITE to write the contents of "cdata" to a bitmap image.
imwrite(f.cdata,'img.bmp','bmp');
1 Comment
darova
on 16 May 2020
How to control quality image? As i know getframe and imwrite have no this option
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!