Changing color of scatter point based on axis
31 views (last 30 days)
Show older comments
Hi,
I am working on a scatter plot that has a temperature vector on the x-axis and an elevation vector on the y-axis. So my scatter function looks similar to scatter(temp,topo).
I would like to be able to make the points associated with the x-axis all one color (red, for example) and the points associated with my y-axis all one color(black lets say).
Here is an example of my current plot:
Answers (1)
Chad Greene
on 15 Jul 2014
This is a confusing question. All points are associated with the x and y axes, no?
To change the color of the points, include the RGB values you want as the fourth argument in scatter. The third argument corresponds to the marker size.
Below, I've created some flags. All the points in some range of x values get colored red and all the points bound by the upper right box in xy get colored blue.
x = 1:100;
y = rand(size(x));
flag = NaN(size(x));
flag(x>10&x<50) = 1;
flag(y>.2&x>60) = 2;
colors = zeros(length(x),3);
colors(flag==1,1) = 1;
colors(flag==2,3) = 1;
scatter(x,y,50,colors,'filled')
0 Comments
See Also
Categories
Find more on Scatter Plots 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!