Color Scatter plot based on values in another column
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
dpb
le 25 Sep 2022
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 commentaires
Voir également
Catégories
En savoir plus sur Data Distribution Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!