フィルターのクリア

plot legend that depicts different markes of nodes

1 回表示 (過去 30 日間)
Rub Ron
Rub Ron 2023 年 3 月 23 日
コメント済み: Rub Ron 2023 年 3 月 23 日
I want to have a legend that label the markers present in my graph plot.
G = graph([1 1], [2 3]);
plot(G,'marker',[{'o'},{'x'},{'+'}])
Legend should show:
o one
x two
x three

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 3 月 23 日
That's why if you directly use legend after creating the graph, you will get the graph as the legend identifier.
There is a work around to achieve what you want to do -
str=[{'o'},{'x'},{'+'}];
clr='b';
figure
hold on
for k=1:numel(str)
plot(NaN,NaN,[clr str{k}])
end
G = graph([1 1], [2 3]);
plot(G,'NodeColor',clr,'EdgeColor',clr,'Marker',str,'MarkerSize',6)
legend({'one', 'two', 'three'})
  1 件のコメント
Rub Ron
Rub Ron 2023 年 3 月 23 日
I would just add:
plot(NaN,NaN,[clr str{k}],'MarkerFaceColor',clr)
to fill the marker.

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

その他の回答 (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