Adding a legend to a Graph in Matlab

18 ビュー (過去 30 日間)
Arham Mini
Arham Mini 2021 年 11 月 10 日
回答済み: Bjorn Gustavsson 2021 年 11 月 10 日
I'd like to add a legend in my Graph without dividing it in several graphs (which is the suggestion made in Legend in a Graph - MATLAB Answers - MATLAB Central (mathworks.com)).
My graph is this one:
I've generated it using plot() and highlight() (for different shapes and colours of nodes of interest). I'd like to generate a legend with the different shapes and colors, because they represent different groups of people but they are part of the same graph. I tried using text() but it's not what I'm looking for as I can't generate a legend with the symbols and colors.

回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2021 年 11 月 10 日
Would something like:
legend([h(idx1(1)),h(idx1(2)),h(idx3(1))],...
'label1','label2','label3')
work for this case. Here I have set the output from your call to plot to h and the three (?) different highlights to be done with something like this:
highlight(h,idx1,etc..)
highlight(h,idx2,etc..)
highlight(h,idx3,etc..)
HTH

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by