Changing orientation of color map

50 visualizaciones (últimos 30 días)
Sabyrzhan Yeginbayev
Sabyrzhan Yeginbayev el 11 de Oct. de 2021
Editada: Image Analyst el 15 de Oct. de 2021
How can I change the orientation of color difference from horizontal to vertical. Now it becomes "cooler" from 0 to x. as shown in first screenshot, but I want it to become cooler in y direction as in second screenshot
x = linspace(0,3*pi,200);
y = (cos(x) + rand(1,200))*(-1);
size=(10*x+0.01);
colormap cool
c = linspace(1,-10,length(x));
scatter(x,y,size,c, 'filled')
<-- My result <-- Preferred Result

Respuesta aceptada

Image Analyst
Image Analyst el 11 de Oct. de 2021
Editada: Image Analyst el 15 de Oct. de 2021
Try using the scaled y values as the index into your colormap:
x = linspace(0,3*pi,200);
y = (cos(x) + rand(1,200))*(-1);
sizes = (10*x+0.01);
cmap = cool(256);
% Get the row of cmap that corresponds to the y value.
rows = round(rescale(y, 1, size(cmap, 1)));
colors = cmap(rows, :);
scatter(x, y, sizes , colors, 'filled')
grid on;
To reverse the colors, use fllipud() on the colormap.
x = linspace(0,3*pi,200);
y = (cos(x) + rand(1,200))*(-1);
sizes = (10*x+0.01);
cmap = flipud(cool(256));
% Get the row of cmap that corresponds to the y value.
rows = round(rescale(y, 1, size(cmap, 1)));
colors = cmap(rows, :);
scatter(x, y, sizes , colors, 'filled')
grid on;

Más respuestas (1)

Oguzhan Alkan
Oguzhan Alkan el 15 de Oct. de 2021
The orientation of color difference is changed from horizontal to vertical.
Does anyone know how to do this? This is what should be done in the assignment
  1 comentario
Image Analyst
Image Analyst el 15 de Oct. de 2021
Not sure what you mean. The colors of the markers DO change as you move vertically.
If you want the colors to change horizontally, just change y to x:
x = linspace(0,3*pi,200);
y = (cos(x) + rand(1,200))*(-1);
sizes = (10*x+0.01);
cmap = cool(256);
% Get the row of cmap that corresponds to the x value.
rows = round(rescale(x, 1, size(cmap, 1)));
colors = cmap(rows, :);
scatter(x, y, sizes , colors, 'filled')
grid on;
Again, explain exactly what you mean because you seem to be asking for exactly what my accepted answer already does. What do you want different????

Iniciar sesión para comentar.

Categorías

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

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by