diff options
author | Ross Barnowski <rossbar@berkeley.edu> | 2021-01-15 20:52:13 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-15 23:52:13 -0500 |
commit | 7f2eed63562f52fb5dd8fb58da4a8237ffc794d7 (patch) | |
tree | e29c9283d114bf56267adfdd19a9db637883a57f | |
parent | b515ba63e731cf3eb5efda10e47acb1e2b3abbf7 (diff) | |
download | networkx-7f2eed63562f52fb5dd8fb58da4a8237ffc794d7.tar.gz |
Partially revert #4378 - Modify behavior of nodelist param in draw_networkx_edges. (#4531)
* Revert #4378 - Modify behavior of nodelist param in draw_networkx_edges.
Docstring changes are retained.
* update docstring for nodelist
Co-authored-by: Dan Schult <dschult@colgate.edu>
-rw-r--r-- | networkx/drawing/nx_pylab.py | 16 | ||||
-rw-r--r-- | networkx/drawing/tests/test_pylab.py | 20 |
2 files changed, 5 insertions, 31 deletions
diff --git a/networkx/drawing/nx_pylab.py b/networkx/drawing/nx_pylab.py index 70016621..e88f2bce 100644 --- a/networkx/drawing/nx_pylab.py +++ b/networkx/drawing/nx_pylab.py @@ -566,10 +566,8 @@ def draw_networkx_edges( Size of nodes. Though the nodes are not drawn with this function, the node size is used in determining edge positioning. - nodelist : list (default=list(G)) - Only draw edges that are in `edgelist` and that lie between nodes in - `nodelist`. Any edges in `edgelist` incident on nodes that are *not* in - `nodelist` will not be drawn. + nodelist : list, optional (default=G.nodes()) + This provides the node order for the `node_size` array (if it is an array). node_shape : string (default='o') The marker used for nodes, used in determining edge positioning. @@ -641,16 +639,12 @@ def draw_networkx_edges( if edgelist is None: edgelist = list(G.edges()) - if nodelist is None: - nodelist = list(G.nodes()) - else: - # Remove any edges where both endpoints are not in node list - nodeset = set(nodelist) - edgelist = [(u, v) for u, v in edgelist if (u in nodeset) and (v in nodeset)] - if len(edgelist) == 0: # no edges! return [] + if nodelist is None: + nodelist = list(G.nodes()) + # FancyArrowPatch handles color=None different from LineCollection if edge_color is None: edge_color = "k" diff --git a/networkx/drawing/tests/test_pylab.py b/networkx/drawing/tests/test_pylab.py index 6b374029..fd0e9466 100644 --- a/networkx/drawing/tests/test_pylab.py +++ b/networkx/drawing/tests/test_pylab.py @@ -309,8 +309,6 @@ def test_draw_edges_min_source_target_margins(node_shape): assert padded_extent[0] > default_extent[0] # And the rightmost extent of the edge, further to the left assert padded_extent[1] < default_extent[1] - # NOTE: Prevent axes objects from impacting other tests via plt.gca - plt.delaxes(ax) def test_nonzero_selfloop_with_single_node(): @@ -358,21 +356,3 @@ def test_apply_alpha(): alpha = 0.5 rgba_colors = nx.drawing.nx_pylab.apply_alpha(colorlist, alpha, nodelist) assert all(rgba_colors[:, -1] == alpha) - - -@pytest.mark.parametrize( - ("nodelist", "expected_num_edges"), - ( - ([], 0), - ([1], 0), - ([1, 2], 1), - ([0, 1, 2, 3], 6), - ), -) -def test_draw_edges_with_nodelist(nodelist, expected_num_edges): - """Test that edges that contain a node in `nodelist` are not drawn by - draw_networkx_edges. See gh-4374. - """ - G = nx.complete_graph(5) - edge_patches = nx.draw_networkx_edges(G, nx.circular_layout(G), nodelist=nodelist) - assert len(edge_patches) == expected_num_edges |