Changing colorscale increments on a surface plot
6 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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 件のコメント
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
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
2014 年 9 月 24 日
Not exactly sure what that means, but have you checked out the caxis() function?
参考
カテゴリ
Help Center および File Exchange で Color and Styling についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!