How to plot a jet colour bar for specific values ?
16 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
My script works perfectly, but I unable to set the color bar as jet. May someone suggets a possible way out. Thanks
Scripts is as below:
lear all
clc
X = load('PDS_case.csv'); % input data
C_sort = sortrows(X,5);
Tri = C_sort(1:86,:);
data1 = sortrows(Tri,7);
PDS=(data1(:,7))';
data2=data1(:,8:66);
data4=data2';
Y=data4(:,1:86);
X=Y';
UU=[2e-8, 4e-8, 6e-8, 8e-8, 1e-7, 3e-7]; % these values linked with each color bar, should be make a color bar
r{1}=[X(1:60,:)];
r{2}=[X(61:68,:)];
r{3}=[X(69:76,:)];
r{4}=[X(77:79,:)];
r{5}=[X(80:81,:)];
r{6}=[X(82:85,:)];
figure
cm = colormap(jet(numel(r)));
cc = colorbar('vert');
set(cc,'Ticks',((1:numel(UU))/numel(UU))');
set(cc,'TickLabels',num2str(UU'));
ylabel(cc,'PDS')
hold on
for k = 1:numel(r) % ... Then, Remove The 'NaN' Elements ...
ra = r{k};
ra = ra(~isnan(ra));
[f ,x ] = ecdf(ra);
[x ,ia ,ic ] = unique(x);
f = f(ia );
xx = linspace(min(x ),max(x ),100);
ff = interp1(x ,f ,xx );
ffs = smoothdata(ff , 'loess',10);
dx = mean(diff(xx ));
dfdxs = gradient(ffs )./dx ;
plot(xx , dfdxs , '-', 'linewidth', 1, 'Color',cm(k,:))
ylim([0, 8])
xlabel('R')
ylabel('Probability Density')
end
hold off
%grid
Here is what i get
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/947329/image.png)
Here is wnt i expect (two thing jet color bar and scale shold be like power only)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/947334/image.png)
0 个评论
回答(1 个)
KSSV
2022-3-31
This line:
cm = colormap(jet(numel(r)));
You are limiting the colorbar to only six colors. So you are getting the colorbar as you shown. Replace the line with:
cm = colormap(jet); % or may be you can use more number than 6, like 32 or 64..
For the second part of the question, you need to play with ticklabels. May be refer this for demo:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Red 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!