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

Allow edge style to be a list of styles for DiGraphs #5131

Merged
merged 15 commits into from
Oct 16, 2021
Merged

Conversation

mgbckr
Copy link
Contributor

@mgbckr mgbckr commented Oct 15, 2021

Fixes issue where DiGraphs fail to allow a list of edge styles (or when enabling arrows=True for Graph):

import networkx as nx
import matplotlib.pyplot as plt

g = nx.DiGraph()
g.add_nodes_from([0,1,2])
g.add_edges_from([(0,1), (0,2)])

nx.draw_networkx_nodes(g, pos=[(0,0), (0,1), (1,0)])
nx.draw_networkx_edges(g, pos=[(0,0), (0,1), (1,0)], style=["-", "--"],)

This throws an error:

ValueError: Unrecognized linestyle: ['-', '--']

The proposed pull request fixes this issue.

@dschult
Copy link
Member

dschult commented Oct 15, 2021

Thanks for this idea and for the code! :}

Could you make the if/else logic match that for width which is just before your code for linestyle?
Also, could you add tests for ensure that it is working?

@dschult dschult added this to the networkx-2.7 milestone Oct 15, 2021
@mgbckr
Copy link
Contributor Author

mgbckr commented Oct 15, 2021

Hi Dan, updated the logic style and added some tests. Let me know if you need anything else.

Copy link
Member

@dschult dschult left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me!
Thanks!

Copy link
Contributor

@rossbar rossbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mgbckr , this seems like an obvious improvement to me!

I had a couple suggestions about cleaning up the logic a bit and making the added tests a bit more rigorous. One other thing is that the style parameter in the Parameters list of the draw_networkx_edges docstring should be updated to reflect this change.

networkx/drawing/nx_pylab.py Outdated Show resolved Hide resolved
networkx/drawing/tests/test_pylab.py Outdated Show resolved Hide resolved
Copy link
Contributor

@rossbar rossbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, thanks @mgbckr !

@rossbar rossbar merged commit d7021f5 into networkx:main Oct 16, 2021
dschult pushed a commit to dschult/networkx that referenced this pull request Jan 25, 2022
Support sequences of linestyles for directed edges in `draw_networkx_edges`.
MridulS pushed a commit to MridulS/networkx that referenced this pull request Feb 4, 2023
Support sequences of linestyles for directed edges in `draw_networkx_edges`.
cvanelteren pushed a commit to cvanelteren/networkx that referenced this pull request Apr 22, 2024
Support sequences of linestyles for directed edges in `draw_networkx_edges`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants