Use fixed colormap or colorbar scale for series of 3D bar graphs in video animation
조회 수: 6 (최근 30일)
이전 댓글 표시
I've been able to incorporate code from this answer:
...in order to set uniform colors to bars in bar3() plots based on height. I would like the color scale to be fixed (10=burgendy, 0=navy) throughout all plots; however, it seems to be relative based on the max/min of each one. I tried setting c.TicksLimit=[0 10] but that didn't work. It's quite possible there's an entirely better/different approach for this 3D visualization. I am open to a changeup but also would appreciate the opportunity to better undestand bar3() and figure properties. Thank you for your time and assistance.
Here's the current animation produced from the code below to help visualize. Ideally, the initial condition would be all burgendy bars, and the colorbar would be fixed all through the animation from 0 to 10.
function animator(frames)
filename = 'animation.mp4';
v=VideoWriter(filename,'MPEG-4');
v.FrameRate=2;
open(v);
for i1=1:length(frames)
active=frames(:,:,i1);
b=bar3(active);
colormap(turbo(10)); %% Perhaps something 'smart' happens here instead of fixed turbo(10)
% to set the colormap based on relative max/min?
set(gca,'ZLim',[0 10]);
% Copied from above link and properly colors all bars to same color
% based on height
numBars=size(active,1);
numSets=size(active,2);
for i2=1:numSets
zdata=ones(6*numBars,4);
k=1;
for j=0:6:(6*numBars-6)
zdata(j+1:j+6,:)=active(k,i2);
k=k+1;
end
set(b(i2),'Cdata',zdata)
end
c=colorbar;
c.Ticks=0:10;
% Or maybe something happens here to fix the colorbar scale?
exportgraphics(gca,'temp.png');
im=imread('temp.png');
im=imresize(im,[560 730]);
writeVideo(v,im);
end
end
댓글 수: 0
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Orange에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!