Effacer les filtres
Effacer les filtres

how to add a corresponding colorbar with a plot lines

3 vues (au cours des 30 derniers jours)
TESFALEM ALDADA
TESFALEM ALDADA le 6 Nov 2021
Hello guys,
I created a plot with the color bar. But i couldnot make sure that the color scales on the plot are matching with the colorbar.
For the code below the respective image is shown. And i wanted to assign a value of 1 to dark gray and 0 to light gray in the colorbar.
I will appreciate your kind response.
%%
y=1+rand(10,10)*9;
col = ones(10,3).*rand(10,1);
col = sort(col,'ascend');
colormap(gray(10))
for i=1:10
plot([1 10],[1 10]); hold on
plot(y(:,i),'LineWidth',1,'color',col(i,:));
hc = colorbar;
cb=[0:0.1:1]';
set(hc, 'YTick',cb,'YTickLabel',cb,'TicksMode','auto')
end

Réponse acceptée

DGM
DGM le 7 Nov 2021
Just flip the colormap.
y=1+rand(10,10)*9;
col = ones(10,3).*rand(10,1);
col = sort(col,'ascend');
plot([1 10],[1 10]); hold on
for i=1:10
plot(y(:,i),'LineWidth',1,'color',col(i,:));
end
hc = colorbar;
colormap(flipud(gray(10)))

Plus de réponses (0)

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by