Is there a tool to create legends for directed/undirected graphs?
1 view (last 30 days)
Show older comments
Denman James
on 24 Apr 2018
Answered: Michael Moore
on 24 Jan 2020
I've been playing with the directed graphing abilities and finding it to work very well. I am able to create some neat graphs that contain a lot of information packed in for visual communication in particular - setting node colors, edge color, etc. I'm finding that I'm not able to create a legend for this sort of work and have been slowly building one in a clunky way via a separate plot. Is there a utility for doing this sort of thing that I missed in the documentation?
0 Comments
Accepted Answer
Walter Roberson
on 24 Apr 2018
No, you did not miss anything. graph objects have no useful legend.
There is a getLegendGraphic() method that can be applied to the object returned by the plot() call. That gets you a hggroup whose children you can examine. However, when I change the properties of those, nothing appears to happen. The items do not appear to have properties that can go into a legend.
You do not need another plot, though. What you can do is line() a bunch of items together using nan, nan as the coordinate and appropriate color and linestyle and marker properties, and giving them DisplayName properties that you want to appear in the legend. Then legend() that group of handles. Because the coordinates are nan, the lines will not be drawn, but the information for them will appear in the legend.
More Answers (1)
Michael Moore
on 24 Jan 2020
I am using digraphs to for my network algorithms. I am using the plot command intended for graphs and digraphs (use help digraph/plot for more info), which is different than the plot command for normal fugures. The legend function does not seem to wirk as usual when applied to digraph plots.
However, in nevertheless using the normal legend command on my digraph plots, I get an interesting result. The result is a picture of a small network with 4 nodes, and whatever strings I have tried to use as labels concantenated together. With a little more fudging, I could probably get what I really want.
0 Comments
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!