Warn on unused visualization kwargs that only apply to FancyArrowPatch edges #6098
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 graphG
is undirected, and FAPs are used whenG
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 thearrows
kwarg:arrows=True
will forcedraw_networkx_edges
to use FAPs even ifG
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 usingarrows=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.