Can I reorder the legend entries for gscatter

9 ビュー (過去 30 日間)
Heidi Hirsh
Heidi Hirsh 2019 年 3 月 21 日
コメント済み: Heidi Hirsh 2019 年 3 月 24 日
I am making a gscatter plot where the groups are depths. I want the depths to be in order from shallowest to deepest in the legend (in this case = S, 1T, 10B, 4B, 1B). Can I control that somehow? Right now the legend is just the default.
f2=figure(2)
gscatter(TA_est,TA_meas,strtrim(height))
hold on;
plot(alk,alk)
xlabel('LIAR TA','fontsize',16)
ylabel('Measured TA','fontsize',16)

回答 (1 件)

dpb
dpb 2019 年 3 月 21 日
Yeah, just redo the legend manually with the handles in the desired ordered...
...
hGS=gscatter(TA_est,TA_meas,strtrim(height)); % save the GS line handles array
hLG=legend([hGS(...)],' S', '1T', '10B', '4B', '1B');
where [hGS(...)] represents the handles to the array of lines in the order of depth desired associated with the original order. You don't give the data so can't actually determine what that order would be.
  5 件のコメント
dpb
dpb 2019 年 3 月 24 日
Did you try it? <VBG>
Looks like...
Heidi Hirsh
Heidi Hirsh 2019 年 3 月 24 日
So I did this:
hGS=gscatter(TA_est,TA_meas,strtrim(height));
idxOrderWanted = [1 5 3 2 4]
hLG=legend([hGS(idxOrderWanted)],'S', '1T', '10B', '4B', '1B');
BUT when I replotted the figure it looks like the data is now mislabeled. The points are all the same but the colors now match different IDs...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by