bar3 color

조회 수: 5 (최근 30일)
Emily
Emily 2011년 4월 30일
댓글: Shaimaa Doma 2020년 3월 11일
Hello,
I have been using bar3 to plot a matrix. The matrix is 101x 201. When I use bar3, it plots bars of the same color for the short axis, but changes the color for the long axis. For example, my matrix is A(201,101). Matlab plots A(1,:) of the same color, but instead, I want it to plot A(:,1) of the same color. I have tried using bar3(A') but this does not help. Does anyone have sugestions?
Many thanks

답변 (1개)

Sarah Wait Zaranek
Sarah Wait Zaranek 2011년 5월 2일
I believe this will work for you. Basically I am resetting each set of bars colormap by changing the CData of the patches that make up the bar. I kept the original plot as a reference in this example.
A = rand(101,201);
figure;
hc = bar3(A);
figure;
h = bar3(A);
for ii = 1:length(h)
zdata = get(h(ii),'ZData');
colorEx = repmat((1:length(zdata))',[1 4]);
set(h(ii),'CData',colorEx)
end
  댓글 수: 1
Shaimaa Doma
Shaimaa Doma 2020년 3월 11일
If I understand the question correctly, the code works when zData and not colorEx is used as color information:
set(h(ii),'CData',zdata)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by