Clear Filters
Clear Filters

how to add a corresponding colorbar with a plot lines

3 views (last 30 days)
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

Accepted Answer

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

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!