Color Scatter plot based on values in another column

23 visualizaciones (últimos 30 días)
Davin David
Davin David el 25 de Sept. de 2022
Respondida: dpb el 25 de Sept. de 2022
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.

Respuestas (1)

dpb
dpb el 25 de Sept. de 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.

Productos


Versión

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by