我在同一个轴上绘制了许多图像的循环,以制作视频。不幸的是,色条的存在使循环变得更加缓慢。即使我使用caxis('manual')“冻结”了颜色栏,也会发生这种情况。
为什么?我想可能仍然会有听众放慢整个过程,但这真的很糟糕。冻结色条后,没有任何计算应该涉及到它。
这是一个演示,演示了colorbar的一些工作原理,主要目的是冻结它。下面的代码中没有循环。
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!发布于 2014-01-24 02:22:14
这比我预想的更有趣。我没有答案,但有一系列的例子证明了一些非答案。也许比我聪明的人会有更好的运气。
例如,使用colorbar:
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)发布于 2014-01-24 22:51:11
多亏了对这个问题的进一步调查,这个问题似乎太深了,无法妥善解决。
由于没有找到一个好的标准解决方案,我求助于在单独的子图中制作自己的颜色条。然后在循环过程中保持不变。为了制作自己的颜色栏,我推荐使用subplot(1,5,1:4)作为主图,subplot(1,5,5)作为颜色栏。然后,您只需再次使用imagesc绘制caxis的线性空间,即可生成颜色栏。提供y刻度,删除x刻度。
https://stackoverflow.com/questions/21315626
复制相似问题