Assign specific color to legend based on specific values.
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
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 Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!