Clear Filters
Clear Filters

plot legend that depicts different markes of nodes

5 views (last 30 days)
I want to have a legend that label the markers present in my graph plot.
G = graph([1 1], [2 3]);
Legend should show:
o one
x two
x three

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 23 Mar 2023
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 -
hold on
for k=1:numel(str)
plot(NaN,NaN,[clr str{k}])
G = graph([1 1], [2 3]);
legend({'one', 'two', 'three'})
  1 Comment
Rub Ron
Rub Ron on 23 Mar 2023
I would just add:
plot(NaN,NaN,[clr str{k}],'MarkerFaceColor',clr)
to fill the marker.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!