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

Warn on unused visualization kwargs that only apply to FancyArrowPatch edges #6098

Merged
merged 4 commits into from
Oct 22, 2022

Conversation

rossbar
Copy link
Contributor

@rossbar rossbar commented Oct 18, 2022

Closes #5857 and #5694

draw_networkx_edges has a few keyword arguments that only apply when FancyArrowPatch (FAP) objects are used to represent the edges (as opposed to a LineCollection (LC)). The tricky part is that the logic for determining which object is used is not immediately clear to the user. By default, LCs are used when the input graph G is undirected, and FAPs are used when G is directed. The reason for this is that LC are much faster to draw than FAPs, so using LCs where possible greatly enhances the ability to visualize graphs with many edges. The default behavior can be overridden with the arrows kwarg: arrows=True will force draw_networkx_edges to use FAPs even if G is undirected. This may make the visualization much slower, especially if there are a lot of edges, but the tradeoff is that the user can then take advantage of FAP-specific features, like the ability to draw curved edges.

This PR introduces UserWarnings whenever a user calls draw_networkx_edges with a FAP-specific kwarg when LC is being used to draw the edges. The current behavior is to silently ignore the FAP-specific kwarg which leads to confusion - see e.g. #5857 and #5694. The warning message specifies how to fix the situation, either by using arrows=True to force FAPs (which may be slow) or by deleting the unused kwarg option if it is not needed.

The hope is that the warning is useful without being noisy - note that adding it in caught one instance in the NX test suite where kwargs were silently ignored. The other concern is that the warnings are not raised when they shouldn't be - I double checked the output of the gallery examples to ensure that there were no new, unexpected warnings from this change.

@rossbar rossbar added type: Enhancements Visualization Related to graph visualization or layout labels Oct 18, 2022
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.

LGTM!

@dschult dschult merged commit 73afc67 into networkx:main Oct 22, 2022
Mjh9122 pushed a commit to Mjh9122/networkx that referenced this pull request Oct 22, 2022
…h edges (networkx#6098)

* Add test for UserWarning with ignored vizopts.

* Implement UserWarning for bad vizopts combos.

* Fix instance in test suite caught by new warnings.

* Update test to check warnings are *not* raised when using FAPs.
MridulS pushed a commit to MridulS/networkx that referenced this pull request Feb 4, 2023
…h edges (networkx#6098)

* Add test for UserWarning with ignored vizopts.

* Implement UserWarning for bad vizopts combos.

* Fix instance in test suite caught by new warnings.

* Update test to check warnings are *not* raised when using FAPs.
cvanelteren pushed a commit to cvanelteren/networkx that referenced this pull request Apr 22, 2024
…h edges (networkx#6098)

* Add test for UserWarning with ignored vizopts.

* Implement UserWarning for bad vizopts combos.

* Fix instance in test suite caught by new warnings.

* Update test to check warnings are *not* raised when using FAPs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: Enhancements Visualization Related to graph visualization or layout
3 participants