Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

Technical Solutions

How do I print or save one axes from a set of axes and objects in a figure window?


Date Last Modified: Friday, June 26, 2009
Solution ID:   1-18VP2
Product:   MATLAB
Reported in Release:   R13
Platform:   All Platforms
Operating System:   All OS
 

Subject:

How do I print or save one axes from a set of axes and objects in a figure window?

Problem Description:

I would like to know how to print or save one axes from a set of axes and objects in a figure window.

Solution:

There is no direct way to print a specific axes from a figure window, because the print routine is associated with the figure window rather than an axes. Since all the axes are part of one figure, you cannot print just one from it directly. However, you can use the COPYOBJ function to copy the required axes to a new figure and then print that figure window. For example:

% make a figure with several axes
fig1 = figure;
xx = 0:pi/10:2*pi;
sp(1) = subplot(3,1,1);
plot(xx, 10*sin(xx));
sp(2) = subplot(3,1,2);
plot(xx, cos(xx));
sp(3) = subplot(3,1,3);
plot(xx, tan(xx));

% create a new figure for saving and printing
fig2 = figure('visible','off');
% copy axes into the new figure
newax = copyobj(sp(1),fig2);

% If you would like to have the axes cover a larger area of the figure window rather
% than the original size as in the subplot, then change it's Position value:
set(newax, 'units', 'normalized', 'position', [0.13 0.11 0.775 0.815]);

% print and/or save the figure
print(fig2) % print it
hgsave(fig2,'myfig') % save it
close(fig2) % clean up by closing it

Now you can use the PRINT command, Print menu, or SAVEAS command to print the figure, export it to a graphics file, or save it to a FIG-file.

Please provide feedback to help us improve this Solution
Contact support
E-mail this page
Print this page