Animation Slow Due to ColorBar.doUpdate Function
6 次查看(过去 30 天)
显示 更早的评论
I'm trying to animate a plot with a static colorbar on it.
For some reason a large percentage of my code runtime is spent in this ColorBar.doUpdate function, despite the fact that I am not manually changing any colorbar properties as the code runs.
Is there a way to force Matlab to keep the properties of the colobar static (and not even attempt to update the colorbar) even as the graph limits are updated?
Here is an example that mimics the issue I am seeing.
clear all
close all
% params
R = 10;
dtheta = deg2rad(1);
max_theta = 3*(2*pi);
% initalize figure
figure;
% xlim(1.5*R*[-1 1]); % static limits
% ylim(1.5*R*[-1 1]);
grid('on');
colorbar;
colormap('jet');
% main loop
rect = rectangle;
for theta=0:dtheta:max_theta
x = R*cos(theta);
y = R*sin(theta);
pos = [x y 1 1];
rect.Position = pos;
xlim(1.5*R*[-1 1]); % dynamic limits
ylim(1.5*R*[-1 1]);
drawnow;
end
If the axes' limits are static and there is no colorbar, the code runs in ~7.3 seconds on my machine.
If the axes' limits are updated in the for loop but there still is no colorbar, the code runs in ~12.6 seconds.
If the axes' limits are updated in the for loop and there is a colorbar, the code runs in ~24.7 seconds!
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!