Color Scatter plot based on values in another column
조회 수: 19 (최근 30일)
이전 댓글 표시
I have a .csv file with some columns of data. I want to scatter plot 2 columns X and Y, with colors based on their respective values in colimn Z.
These are the groupings for coloring:-
0.5-1.5
1.5-2.0
2.0-2.5
2.5-3.0
3.0-3.5
>3.5
I also want to know how the code will change with the number of groupings. I would also like to know how to create a legend with color and the range and a trendline for the graph.
댓글 수: 0
답변 (1개)
dpb
2022년 9월 25일
You can't use such a grouping as is, create a grouping variable...
edges=[0.5 1.5:0.5:3.5 inf];
g=discretize(Z);
hSC=scatter(X,Y,[],g);
I illustrated the idea of a legend correlated with color just yesterday -- the legend is associated with an object handle, not a property, so you'll have to supply a color for each bin -- the <example> used a fixed color for each scatter object instead so it needed the RGB triplet form instead of being able to use the indexing into a colormap, but the code logic is the same idea as there.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!