Changing color of scatter point based on axis
이전 댓글 표시
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:

답변 (1개)
Chad Greene
2014년 7월 15일
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')
카테고리
도움말 센터 및 File Exchange에서 Scatter Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!