Colour points in 2d or 3d based on value of another vector

7 vues (au cours des 30 derniers jours)
Elliot Ferguson
Elliot Ferguson le 30 Août 2022
Commenté : Elliot Ferguson le 30 Août 2022
I have several parallel vectors of data and I have been plotting them against each other in various ways to determine relationships and develop a model. One thing I would like to do is make a plot with each point coloured based on a further quantity, namely temperature. I have tried experimenting with colormap functions but haven't yet managed to find a satisfactory compact solution.
Something similar to this is what I am going for, it seems much simpler to do with matplotlib.
The temperatures range from roughly 40-100 so 40 should be classed as 'cold' and at the blue end, etc. I am looking for a solution for both 2d and 3d plots as I will be working with both of these.

Réponse acceptée

Cris LaPierre
Cris LaPierre le 30 Août 2022
Modifié(e) : Cris LaPierre le 30 Août 2022
With the scatter function, you can specify the color as a vector of numbers. See this example
x = linspace(0,3*pi,200);
y = cos(x) + rand(1,200);
c = linspace(40,100,length(x));
scatter(x,y,[],c,'filled')
colormap jet
colorbar
You could follow a similar approach using scatter3. The only difference is specifying X,Y and Z. You can find some examples here.
figure
z = cos(x) + rand(1,200);
scatter3(x,y,z,[],c,'filled')
colormap jet
colorbar

Plus de réponses (0)

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by