フィルターのクリア

Use fixed colormap or colorbar scale for series of 3D bar graphs in video animation

14 ビュー (過去 30 日間)
Josh
Josh 2024 年 5 月 17 日
コメント済み: Voss 2024 年 5 月 20 日
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

採用された回答

Voss
Voss 2024 年 5 月 19 日
  2 件のコメント
Josh
Josh 2024 年 5 月 20 日
Thank you
clim([0 10])
did exactly what i wanted
Voss
Voss 2024 年 5 月 20 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrange についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by