assign specific colors to data in plot

7 visualizaciones (últimos 30 días)
Amir Topaz
Amir Topaz el 6 de Feb. de 2021
Comentada: Amir Topaz el 7 de Feb. de 2021
I am trying to assign to a scatter graph 3 specific colors,
I created an array with an assigned value (1,2 and 3) for each color, and it sort of worked, only that the colors selected were not my choice. I want my colors to be green, red and blue, and so far I cant figure out how to do it.
here's the code:
scatter(pressure,temperature,150,color_2,'filled')
color_2 is an array of numbers (e.g. 1, 1, 1, 3, 2, 3, 2, 3, etc..)
as you can see below, it works, only that the colors were not the colors of my choice...
a follow up question: I want to create a legend of my selected colors, and I cant figure that out as well
thanks,
Amir

Respuestas (1)

Walter Roberson
Walter Roberson el 6 de Feb. de 2021
cmap = [0 1 0; 1 0 0; 0 0 1];
cdata = cmap(color_2, :);
scatter(pressure, temperature, 150, cdata, 'filled')
or
cmap = [0 1 0; 1 0 0; 0 0 1];
scatter(pressure, temperature, 150, color_2, 'filled')
colormap(cmap)
  5 comentarios
Walter Roberson
Walter Roberson el 7 de Feb. de 2021
You did not have "hold on"
cmap = [0 1 0; 1 0 0; 0 0 1];
hold on
names = {'monday', 'tuesday', 'wednesday'};
for K = 1 : length(names)
SH(K) = scatter(nan, nan, 15, cmap(K,:));
end
legend(SH, names)
Amir Topaz
Amir Topaz el 7 de Feb. de 2021
true.
thanks a lot, problem solved

Iniciar sesión para comentar.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by