Assign specific color to legend based on specific values.

조회 수: 3 (최근 30일)
Emmanouil Barmpounakis
Emmanouil Barmpounakis 2019년 7월 6일
편집: dpb 2019년 7월 7일
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
Emmanouil Barmpounakis
Emmanouil Barmpounakis 2019년 7월 7일
But this is the answer I've been looking for! : )
dpb
dpb 2019년 7월 7일
편집: dpb 2019년 7월 7일
"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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by