Why are my axes labels clipped or not displayed when using the GETFRAME and/or MOVIE functions in MATLAB?

19 views (last 30 days)
Why are my axes labels clipped or not displayed when using the GETFRAME and/or MOVIE functions in MATLAB?
The following code produces a movie in which the axes are clipped:
Z = peaks(50);
hfig = figure;
hsurf = mesh(Z);
t=linspace(0,2*pi,16);
set(gca,'zlim',[-10 10]);
for i = 1:15,
Zi = Z.*cos(t(i));
set(hsurf,'zdata',Zi,'cdata',Zi);
M(i) = getframe;
end;
figure
movie(M);

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Dec 2021
Edited: MathWorks Support Team on 13 Dec 2021
When using the GETFRAME function without any input arguments, a snapshot of the current axes is taken. Sometimes the axes labels can be clipped when doing this, especially with 3-D plots.
Instead of taking a snapshot of the axes, you should take a snapshot of the figure. You can use the following code as a guide:
hfig = figure;
surf(peaks);
getframe(hfig);
Furthermore, when playing a movie, the default location of the output is in the current axes, and not the current figure. To force it to play in a specified figure, the handle to the figure needs to be passed to the MOVIE function. This will prevent MOVIE from creating a set of axes and playing the frames inside of the axes.
The following example illustrates these concepts:
Z = peaks(50);
hfig = figure;
hsurf = mesh(Z);
t=linspace(0,2*pi,16);
set(gca,'zlim',[-10 10]);
for i = 1:15,
Zi = Z.*cos(t(i));
set(hsurf,'zdata',Zi,'cdata',Zi);
M(i) = getframe(hfig)
end;
figure
movie(gcf,M);
This method of calling the MOVIE function is described in the documentation that can be found at the following URL:

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!