Can users pre-determine the legend location when utiliznig the gscatter function?

4 ビュー (過去 30 日間)
Brad
Brad 2013 年 6 月 26 日
I'm putting together an M-file where I include several group scatter plots. For unknown reasons, I'm unable to pre-determine the legend location (NorthEastOutside). I can determine the location after the plot is created by manually editing the figure properties.
Is this a limitation of the function?
  2 件のコメント
the cyclist
the cyclist 2013 年 6 月 27 日
Are you able to give a small example of what you mean?
Brad
Brad 2013 年 6 月 27 日
Cyclist, I was able to answer my own question.
Lets say we use the Mathworks example for the gscatter function:
load discrim; gscatter(ratings(:,1),ratings(:,2),group,'br','xo');
This yields the gscatter plot at the link above.
By issuing the following, I can now place the legend in the desired location.
>> legend('data1','data2','location','Northeastoutside')
However, the group IDs are not the same as before (1 and 2 versus data 1 and data 2). I was hoping to find a way where I could relocate the legend without losing the original group IDs. I can maintain the original IDs by placing the legend manually - using the edit figure properties.
Have you run into this before?

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

採用された回答

Brad
Brad 2013 年 7 月 1 日
The current answer is no.
Using the same example as above, the gscatter command will not allow the user to pre-position the legend. One workaround is to find the handle to the legend object and set the legend to the desired position.
load discrim figure, gscatter(ratings(:,1),ratings(:,2),group,'br','xo', [], 'on') % Find the handle to the legend object and set position l= findobj(gcf,'tag','legend'); set(l,'location','northeastoutside');
This answer provided by Amrita Anand (thanks).
  1 件のコメント
Óscar Miranda Domínguez
Óscar Miranda Domínguez 2015 年 3 月 3 日
編集済み: Óscar Miranda Domínguez 2015 年 3 月 3 日
It is easier to just silence the auto legend in gscatter by setting doleg as "off" Next, add the legend. Example:
gscatter(c2,c1,my_labels,my_color,'o+',[],'off');
legend(unique(char(my_labels),'rows'),'location','best')

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

その他の回答 (0 件)

カテゴリ

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