How can I color dots in a 3D Scatter Plot using a separate variable?

10 vues (au cours des 30 derniers jours)
I plotted a 3D score plot as follows:
>> scatter3(score(:,1),score(:,2),score(:,3));
How can I color the dots by an other variable (let us call it Y)?

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 9 Août 2019
You can achieve this by using the below syntax:
>> scatter3(score(:,1),score(:,2),score(:,3),[],Y)
The variable 'Y' has one of the following forms:
1. A three column matrix of RGB triplets — Use different colors for each marker. Each row of the matrix specifies an RGB triplet color for the corresponding marker. The number of rows must equal the length of 'score(:,1)', 'score(:,2)' and 'score(:,3)'.
Example: If you have three points in the scatter plot and want to specify the color corresponding to each marker, specify 'Y' as a three-column matrix of RGB triplets.
Y = [1 0 0 ; 0 1 0 ; 0 0 1]
2. Vector — Use different colors for each marker and linearly map values in 'Y' to the colors in the current colormap. The length of 'Y' must equal the length of 'score(:,1)', 'score(:,2)' and 'score(:,3)'. To change the colormap for the axes, use the 'colormap' function.
Example: If you have three points in the scatter plot and want the colors to be indices into the colormap, specify 'Y' as a three-element column vector.
Y = [1, 2, 3]
You can find an example to vary 'marker color' in a 3D scatter plot in the documentation link below:
In the above example, the vector 'c' corresponds to the 'marker color' and vector 's' corresponds to the 'marker area'.
You can find additional information about these input arguments in the below link:

Plus de réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by