Changing colorscale increments on a surface plot

조회 수: 6 (최근 30일)
Rob
Rob 2014년 9월 23일
댓글: Thomas Carter 2021년 6월 15일
I've got some data which ranges from 1 to around 1E-06 which I am plotting using the mesh function. I'm using the jet colormap which is fine but the color scales goes from 1 to 0.1 in steps of 0.1 and I want it go from 1 to 1E-09 or so in increments of one order of magnitude. i.e. colorscale goes, 1, 0.1, 0.01, 0.001, 1E-04 etc. This will give a broad range of color data and should be fairly intuitive to interpret, currently my surface is nearly all blue as it is not scaling the color.
Some googling suggesting using the set command, but I've not had any success.
I tried:
mesh(X,Y,Z) view(2)
aa = colorbar;
get(aa,'Ytick');
%This returns a vector of [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
%So then if we create a vector tt, with the desired YTick
tt = [1e-10,1e-09,1e-08,1e-07,1e-06,1e-05,1e-04,1e-03,1e-02,1e-01,1]
set(aa,'Ytick',tt);
But this doesn't appear to do anything, the colors on the graph stay the same. Any help which could set me on the right track would be greatly appreciated.
Thanks in advance Rob

채택된 답변

Mike Garrity
Mike Garrity 2014년 9월 24일
I'm afraid that the colormap is always applied as a linear function of the CData. Changing the ticks on the colorbar doesn't change anything about how the colormap is applied, it just changes the values which are displayed on the colorbar.
You've really got two options here.
One is to make your CData be a transformed version of your ZData
C = log10(Z);
mesh(X,Y,Z,C)
The other is to transform the colors in your colormap like so:
ncolorsin = 2048;
ncolorsout = 128;
c = jet(ncolorsin); % Get a big copy of jet
t = linspace(0,1,ncolorsout); % Create a linear ramp the size of the colormap we actually want
t2 = t.^10; % Apply whatever transform you like to the ramp
% Use that to scale the big linear colormap into the small stretched one.
c2 = c(1+floor((ncolorsin-1)*t2'),:);
colormap(c2); % Use that as the colormap
Both approaches have advantages and disadvantages.
  댓글 수: 3
Rob
Rob 2014년 9월 25일
So I tried both methods. The first one is obvious as you just transform the data to what you want.
The second method gives me a lot of blue as because the colormap goes between 0 and 1 any transform has to obey these conditions so you can only easily apply transforms that reduce the values in the colormap.
I think what I will do is just transform the Zdata and then plot it, that way I should be able to apply the same transform to the YTickLabel to keep the numbers sensible.
Thanks for the advice, Rob
Enrico Aymerich
Enrico Aymerich 2020년 12월 1일
편집: Enrico Aymerich 2020년 12월 1일
Actually, the second option is also good, but if the transform is t.^10 the image tends to be saturated to low values (as Rob commented). It seems to work better with t2 = sqrt(t) or similar. I had a similar issue

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

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 9월 23일
You can get up to 256 colors in a colormap
colormap(jet(256));
the default, which you're probably seeing is only 64.
  댓글 수: 3
Image Analyst
Image Analyst 2014년 9월 24일
Not exactly sure what that means, but have you checked out the caxis() function?
Thomas Carter
Thomas Carter 2021년 6월 15일
I like this one, just needed more color on scale.

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

카테고리

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