Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve plotting of self-loops #4551

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Silmathoron
Copy link
Contributor

This is a proposal to update the way self-loops are currently plotted.
I find the current plot slightly strange since the arrow does not end on the node and the loop does not rescale upon zoom contrary to the other edges.

Current behavior from master

Since drawing correct circles is complex and error prone, I propose to reshape the loops as triangles and scale them based on node or edge size.

import networkx as nx
import matplotlib.pyplot as plt

g = nx.DiGraph()

g.add_nodes_from(range(5))

g.add_edges_from(
    [(0, 0), (0, 1), (1, 2), (2, 0), (2, 2), (2, 3), (3, 1), (3, 4), (4, 4)])

fig, axes = plt.subplots(2, 2)

ns = [40, 80, 60, 100, 120]
es = [5, 1, 2, 3, 1, 5, 5, 4, 2]

h = nx.Graph()
h.add_node(0)
h.add_edge(0, 0)

nx.draw(g, ax=axes[0, 0], node_size=ns)
nx.draw_circular(g, ax=axes[0, 1], node_size=ns[::-1])
nx.draw_shell(g, ax=axes[1, 0], node_size=ns, width=es)
nx.draw(h, ax=axes[1, 1])

plt.show()

example of how the new self-loops look on three graph plots and one with a single node

There is still one thing i did not figure out, which is how to prevent them from getting out of the view... any help on that side would be appreciated.

Base automatically changed from master to main March 4, 2021 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant