Changing orientation of color map
49 views (last 30 days)
Show older comments
Sabyrzhan Yeginbayev
on 11 Oct 2021
Edited: Image Analyst
on 15 Oct 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
0 Comments
Accepted Answer
Image Analyst
on 11 Oct 2021
Edited: Image Analyst
on 15 Oct 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;
0 Comments
More Answers (1)
Oguzhan Alkan
on 15 Oct 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 Comment
Image Analyst
on 15 Oct 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????
See Also
Categories
Find more on Purple in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!