Color Scatter plot based on values in another column
10 次查看(过去 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 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!