Displaced axis on figures

I am about to make an animation of changes on a map and I produce several figures to do so with same axis. However, the axis of my figures occationaly changes place slightly. I am using m_map tools to plot:
for i = 1:30
(imports new Data)
m_proj('Stereographic','lon',[-50],'lat',[70],'rad',10,'rectbox','on'); %
m_pcolor(Longitude,Latitude,Data); % Plots the data on a map
m_grid; % Creates a grid on the map
colorbar
set(gca, 'CLim', [-50,165]); % Max and min on colorbar
axis image
end
Why are the figures changing the axis? Thank you in advance.

Answers (1)

I'm guessing your data bounds might be changing with each frame? I recommend doing as little as possible inside the loop. Instead of initializing a new projection for each frame, just initialize once. And instead of calling a colorbar multiple times, just call it once. The axis image command is probably where the limits are getting altered--so instead of letting axis image decide how to set the axis limits, set them explicitly. Like this:
% First frame:
m_proj('Stereographic','lon',[-50],'lat',[70],'rad',10,'rectbox','on'); %
h = m_pcolor(Longitude,Latitude,Data); % Plots the data on a map
m_grid; % Creates a grid on the map
cb = colorbar;
ylabel(cb,'my colorbar');
caxis([-50,165]); % Max and min on colorbar
axis image
ax = axis;
% All the other frames:
for k = 2:30
(imports new Data)
set(h,'CData',Data)
caxis([-50,165]);
axis(ax)
end
I changed your i variable to k because i is built-in as the imaginary unit.

Asked:

on 29 Apr 2015

Answered:

on 30 Apr 2015

Community Treasure Hunt

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

Start Hunting!