Colorbar减慢了情节

时间:2014-01-23 17:43:54

标签: matlab plot colorbar

我正在同一轴上的循环中绘制许多图像来制作视频。不幸的是,色条的存在使得循环变得更加缓慢。即使我使用caxis('manual')“冻结”了颜色条,也会发生这种情况。

为什么呢?我想仍然可能有听众放慢整个事情,但这真的很糟糕。冻结了颜色条后,不应该进行任何计算。

这是一个演示,说明了彩条的一些工作方式,主要是为了冻结它。以下没有循环。

close all
figure(1);
C = gallery('randcorr',10);
ih = imagesc(1*C);
ch = colorbar;
% The colorbar disappears...
ih = imagesc(2*C);
% Must hold plot in order for it not to disappear
hold on
ch = colorbar;
% Now, even though it doesn't disappear, it still changes!
ih = imagesc(3*C);
% Even if we use a lower lever function
set(ih,'CData',4*C);
% We must do this to freeze the colorbar
caxis('manual')
set(ih,'CData',5*C);
ih = imagesc(6*C);
% That worked!

2 个答案:

答案 0 :(得分:3)

这比我预期的更有趣。我没有答案,但有一些例子展示了一些非答案。也许比我更聪明的人会有更好的运气。

示例,带有颜色条:

figure;
C = gallery('randcorr',10);
ih = imagesc(1*C);
ch = colorbar;
caxis([-2 2])
tic; 
for ix = 1:100
    set(ih,'CData',gallery('randcorr',10));
    drawnow
end
toc;  %2.7 seconds

没有彩条

figure;
C = gallery('randcorr',10);
ih = imagesc(1*C);

caxis([-2 2])    
tic; 
for ix = 1:100
    set(ih,'CData',gallery('randcorr',10));
    drawnow
end
toc;  %0.67 seconds

是什么导致了从2.7到0.67秒的变化?

色条实际上只是一种特殊的轴,所以问题可能是图中有一个以上的有趣轴

figure;
subplot(2,1,1)
C = gallery('randcorr',10);
ih = imagesc(1*C);
subplot(2,1,2)
C = gallery('randcorr',10);
ih2 = imagesc(1*C);

caxis([-2 2])    
tic; 
for ix = 1:100
    set(ih,'CData',gallery('randcorr',10));
    drawnow
end
toc;  %0.87 seconds (consistently slower,  but not enough)

可能属性链接导致速度减慢

figure;
subplot(2,1,1)
C = gallery('randcorr',10);
ih = imagesc(1*C);
subplot(2,1,2)
C = gallery('randcorr',10);
ih2 = imagesc(1*C);
link = linkprop(get(gcf,'children'), 'CLim');

caxis([-2 2])    
tic; 
for ix = 1:100
    set(ih,'CData',gallery('randcorr',10));
    drawnow
end
toc;  %0.88 seconds (pretty much the same as above)

查看默认颜色条,它有很多颜色细节,可能问题只是需要渲染的颜色数量。

figure;
subplot(2,1,1)
C = gallery('randcorr',10);
ih = imagesc(1*C);
subplot(2,1,2)
ih2 = imagesc(repmat(linspace(-2,2,200), 10,1));

caxis([-2 2])    
tic; 
for ix = 1:100
    set(ih,'CData',gallery('randcorr',10));
    drawnow
end
toc;  %0.96 seconds (slower, but still not the 2.7 second colorbar case)

答案 1 :(得分:1)

感谢追求调查的问题,这个问题似乎太深,无法妥善解决。

如果没有找到一个好的标准解决方案,我会在单独的子图中制作自己的颜色条。然后在循环期间保持不变。要制作自己的彩条,我建议使用子图(1,5,1:4)作为主图,使用子图(1,5,5)作为颜色条。然后你再次使用imagesc绘制caxis的linspace来制作颜色条。提供y刻度,删除x刻度。

相关问题