how to add a corresponding colorbar with a plot lines

10 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

DGM
DGM il 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)))

Più risposte (0)

Categorie

Scopri di più su Colormaps in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by