Use fixed colormap or colorbar scale for series of 3D bar graphs in video animation
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Orange in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!