Assign specific color to legend based on specific values.

1 vue (au cours des 30 derniers jours)
Emmanouil Barmpounakis
Emmanouil Barmpounakis le 6 Juil 2019
Modifié(e) : dpb le 7 Juil 2019
I am trying to create a scatter plot with 8 suplots (2x4) with gscatter. The first row plots get data from table A while the second from table B. The two datasets contain a column named "type" which I want to use as group/color in my scatter plots.
Everything works OK but...
While the same values appear in A.type and B.type, they don't get the same color. For example if A.type = 'man' gets green color, while if B.type = 'man' gets a red color which makes it frustrating in order to read on the same plot.
Is there a way to assign specific color to specific values?
Example code:
[...]
subplot(2,4,4)
gscatter(A.parameter3, A.parameter4, A.type);
subplot(1,4,5)
gscatter(B.parameter1, B.parameter2, B.type);
[...]
  7 commentaires
Emmanouil Barmpounakis
Emmanouil Barmpounakis le 7 Juil 2019
But this is the answer I've been looking for! : )
dpb
dpb le 7 Juil 2019
Modifié(e) : dpb le 7 Juil 2019
"gscatter(x,y,group,clr,sym,siz) specifies the color, marker type, and size for each group. clr is either a character array of colors recognized by the plot function or a three-column matrix of color specifications. ... If you do not specify enough values for all groups,gscatter cycles through the specified values as needed."
Write
gscatter(A.parameter3, A.parameter4, A.type,yourcolorordervector);
as the doc instructs...and the example shows changing both the color and symbol for the two groups in the example dataset on the local R2017b doc or actually there's four-group example on current doc at https://www.mathworks.com/help/stats/gscatter.html?s_tid=doc_ta#mw_e8f95d9c-cb60-470e-844d-99fb39693e2f.

Connectez-vous pour commenter.

Réponses (0)

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by