How to plot a jet colour bar for specific values ?

25 visualizaciones (últimos 30 días)
Andi
Andi el 31 de Mzo. de 2022
Comentada: Andi el 31 de Mzo. de 2022
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
Here is wnt i expect (two thing jet color bar and scale shold be like power only)

Respuestas (1)

KSSV
KSSV el 31 de Mzo. de 2022
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:
  1 comentario
Andi
Andi el 31 de Mzo. de 2022
Limits are fix so i only have at max 10 point for color bar.
UU=[1e-8, 2e-8, 3e-8, 4e-8, 5e-8, 6e-8, 7e-8, 8e-8, 9e-8, 1e-7]; % these values linked with each color bar, should be make a color bar
r{1}=[X(1:39,:)];
r{2}=[X(40:60,:)];
r{3}=[X(61:65,:)];
r{4}=[X(66:68,:)];
r{5}=[X(69:74,:)];
r{6}=[X(75:76,:)];
r{7}=[X(77:78,:)];
r{8}=[X(79,:)];
r{9}=[X(80:81,:)];
r{10}=[X(82:86,:)];

Iniciar sesión para comentar.

Categorías

Más información sobre Red en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by