Clear Filters
Clear Filters

scatter3, colors indicate 3dimensions

1 view (last 30 days)
Dear all, I have 3 vectors, flux1, flux2 and temperature, both fluxes depending on temperature. I plotted all 3 in a figure using scatter3. Now I'd like to color the Markerpoints depending on their hight (=according temperature) so that the scatterpoint cloud is easier to read. I know with: scatter3(x,y,z,s,c), c gives an option to do this but I don't seem to understand how to create a c matrix. I randomly tried this:
figure
test = [flux1.';flux2.';temp.'].';
scatter3(flux1,flux2,temp,20,test,'*')
view([10 20])
zlabel('Temperature')
xlabel('sensible heat flux')
ylabel('latent heat flux')
set(gca,'Color',[0.8 0.8 0.8]);
but I'm not happy about it (too much white colored points for high values) and I'd love to actually understand where the coloring comes from my random c-matrix and how I can influence that. Any suggestions and hints? :)
Sorry if this is a very basic question but I couldn't find an answer in the Documentation and I'm pretty new to matlab.

Accepted Answer

Vandana Rajan
Vandana Rajan on 8 Aug 2016
Hi,
To color the marker points according to the temperature intensity, put c = temp. Now the values in 'c' are linearly mapped to the current colormap. The command 'colorbar' shows the current colormap on the side of figure.
clearvars; close all; clc;
%%create the 3 vectors
a = -50;
b = 50;
flux1 = (b-a).*rand(100,1) + a;
flux2 = (b-a).*rand(100,1) + a;
temp = linspace(-5,15,100);
%%when c is of same length as flux1, flux2 and temp, then values in c are linearly mapped to the current colormap
% The command 'colorbar' shows the current colormap on the side of the
% figure
figure;
scatter3(flux1,flux2,temp,20,temp,'*');
zlabel('Temperature')
xlabel('sensible heat flux')
ylabel('latent heat flux')
title('With c = temperature');
colorbar
A number of built-in colormaps are available in MATLAB. You can choose a colormap of your taste. You can also use your own customized colormaps. See this link for more details. http://www.mathworks.com/help/matlab/ref/colormap.html
  1 Comment
Marilena Geng
Marilena Geng on 9 Aug 2016
awesome. So much easier than I thought! :D Thank you!

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!