How can I set a discontinuous colormap and colorbar range?

조회 수: 5 (최근 30일)
Jeng Sze Anselm Ng
Jeng Sze Anselm Ng 2020년 4월 30일
편집: Jeng Sze Anselm Ng 2020년 5월 1일
Hi! I'm trying to define a colorbar for a set of data based off azimuth values (0 - 360 degrees). The azimuth values are categorized into 2 main groups:
1) The signal [351 degrees - 21 degrees inclusive]
2) The noise [21 degrees - 351 degrees exclusive]
Traditionally, for signals with a continuous set of azimuthal values (E.g 67 - 97 degrees), I would:
1) Create a 2D plot based off x and y values using patch, with the polygon's color taking on a single corresponding azimuth value
2) Do this for all data points from the dataset to create multiple polygons that correspond to different x,y and azimuth values
3) Set the colormap to jet
4) Create a colorbar and define CLim to be within the signals range (67 - 97 degrees in this case), such that anything that's outside this range will take on one color (either dark red or blue), where I can see the variation of the signal if for polygons with azimuth values between 67 and 97 degrees. I have attached an image of this result below!
However, as seen above at the start, the signal now has a discontinuous range (351 - 360 degrees AND 0 - 21 degrees), and I'm unable to do what I've done traditionally as mentioned above.
** I tried flipping jet's colomap inside outside, meaning to say i used flipud for the first half of jet's cmap and the same for the second half of the same array, and concatenated the 2 together. I then proceeded to set the Clim of this new cmap to follow the noise [21 351]. However, since my signal follows anything outside CLim in this case, it takes on a rather monochromatic green color, which is not what I wished for as I also wanted to see the variation of the colors within the signal's color range. I have also inserted an image of this result below as a contrast to the one above!**
The thing is, I would like both plots to follow the same colormap regardless of the nature of the azimuthal range of the signal (continuous or discontinuous). Would it be possible for such an scenario? Thank you!
  댓글 수: 2
darova
darova 2020년 4월 30일
Did you try caxis?
caxis([0 100])
Jeng Sze Anselm Ng
Jeng Sze Anselm Ng 2020년 5월 1일
I'll try!! What would be the difference between caxis and clim? I can't find any distinct differences between the 2 apart from knowing both changes the limits of the colorbar!

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

채택된 답변

Sindar
Sindar 2020년 4월 30일
Potential solution:
Shift the data into a continuous range, then relable the colorbar:
cont_data = mydata;
% move [351 - 360 degrees] to [-9 - 0 degrees]
cont_data(cont_data>=351) = cont_data(cont_data>=351)-360;
% <plot>
cb=colorbar();
caxis([-9 21])
discont_ticks = cb.Ticks;
% move labels [-9 - 0 degrees] to [351 - 360 degrees]
discont_ticks(discont_ticks<0) = discont_ticks+360;
cb.TickLabels = discont_ticks;
if you want the noise to all be the same color (e.g., "red outside range"), use a cyclic colormap like hsv or twilight
  댓글 수: 1
Jeng Sze Anselm Ng
Jeng Sze Anselm Ng 2020년 5월 1일
편집: Jeng Sze Anselm Ng 2020년 5월 1일
Thanks!! Works perfectly!!
Found a pretty good cyclic colormap too for Azimuthal data by Matteo Nicolli here!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Color and Styling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by