필터 지우기
필터 지우기

Colorbar doesn't show colours the right way round?

조회 수: 2 (최근 30일)
10B
10B 2017년 5월 25일
답변: Image Analyst 2017년 5월 31일
Hello Community,
I have been bar plotting some data, and have graduated the colours relative to their values in the data which works fine. The issue I am having is that when I call the colorbar - the colours dont match the plotted colour scheme of the data. Following an answer from Image Analyst, I write the graduated bar plot like this:
numberofbars = length(var1);
barColorMap = colormap(summer);
x = 1 : numberofbars;
for b = 1 : numberofbars
% Plot one single bar as a separate bar series.
handleToThisBarSeries(b) = bar(x(b), var1(b));
% Apply the color to this bar series.
set(handleToThisBarSeries(b), 'FaceColor', barColorMap(b,:));
hold on;
end
colorbar
and get this as the output:
which for the bar plot is what I want, but the colorbar colours are inverted to the data. I have tried this to invert the colorbar scheme (following Walter Roberson advice):
oldcmap = colorbar;
colorbar( flipud(oldcmap) );
but unfortunately this doens't sort the colorbar issue in my case.
Does anyone have any advice on how to resolve this please?
Many thanks,
10B.
  댓글 수: 1
10B
10B 2017년 5월 30일
Ah - of course I have also noticed that the colorbar index is not to the correct scale.
Again, any pointers welcome!

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

답변 (2개)

J Philps
J Philps 2017년 5월 31일
편집: J Philps 2017년 5월 31일
Walter was on the right track with his suggestion, but I believe you want to flip the colormap of the colorbar. Here is code demonstrating how you can flip the colormap of the colorbar graphical object:
figure
surf(peaks)
c1 = colorbar;
figure
surf(peaks)
c2 = colorbar;
cmap = colormap;
upside_down_cmap = flipud(cmap);
colormap(c2, upside_down_cmap);

Image Analyst
Image Analyst 2017년 5월 31일
The problem is your chosen color, barColorMap(b,:), should not use b, the loop index, as an index. It should use an index that is chosen according to the height of the bar.

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by