Color Scatter plot based on values in another column
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
dpb
il 25 Set 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 Commenti
Vedere anche
Categorie
Scopri di più su Data Distribution Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!