Borrar filtros
Borrar filtros

how to add a corresponding colorbar with a plot lines

3 visualizaciones (últimos 30 días)
TESFALEM ALDADA
TESFALEM ALDADA el 6 de Nov. de 2021
Comentada: TESFALEM ALDADA el 8 de Nov. de 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

Respuesta aceptada

DGM
DGM el 7 de Nov. de 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)))

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by