필터 지우기
필터 지우기

Colorbar is not representing my current colormap correctly

조회 수: 46 (최근 30일)
Adrian
Adrian 2017년 8월 11일
댓글: Adrian 2017년 8월 11일
Hi There! I made myself a semy custom colormap based on jet with a custom length. I then assign other values I have to each of the colors. In a plot, I plot points colored based on this assignment. When I then use colorbar, it does not contain all of the colors that should be in the colormap. The values that colors get assigned to are negative and positive.
In my sample, I clearly get some bright red spots that are not represented by the colorbar.
here is some sample code:
% sample code
test = rand(2000,3);
colormap = jet(2000);
scatter3(test(1:end,1), test(1:end,2), test(1:end,3),30,colormap,'filled');
colorbar;

채택된 답변

Adam
Adam 2017년 8월 11일
편집: Adam 2017년 8월 11일
You have given true RGB values to scatter3 from mapping your data via the colourmap so the colourmap of the axes is still Parula, which is what the colourbar shows.
When you give colours in true RGB they are unaffected by the colourmap of the axes and giving an instruction to the scatter3 command does not affect the axes colourmap at all.
colormap( jet(2000) )
would set the colourmap of the axes to be the same as your data, but then there is no reason to give true RGB colours to scatter3.
figure; scatter3(test(1:end,1), test(1:end,2), test(1:end,3), 30, 1:2000, 'filled' );
colormap( jet(2000) )
would achieve the same thing. This would also mean that your data is actually affected by the colourmap so if you change it to another one or use caxis to compress it your data will change accordingly. If you don't want this to happen then your original code is fine, but you don't want to put a colorbar up if your data is not using it.
Also don't name a variable colormap - it is the name of the function that sets the colourmap of the axes which you can no longer use because you have hidden it behind a variable name.

추가 답변 (0개)

카테고리

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