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

8 views (last 30 days)
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.

Accepted Answer

Cris LaPierre
Cris LaPierre on 30 Aug 2022
Edited: Cris LaPierre on 30 Aug 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

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!