diff options
| author | Eric Sims <58200144+EricPostMaster@users.noreply.github.com> | 2021-05-12 10:01:19 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-12 10:01:19 -0400 |
| commit | 40656f99a2574fee183a42a2a6167d31cced924d (patch) | |
| tree | c6bf3c1965b3077ac80025dddfc470ce2f1bf34b | |
| parent | f07f1995107aeaaf7ade82e73e83dcf80b94bdfd (diff) | |
| download | networkx-40656f99a2574fee183a42a2a6167d31cced924d.tar.gz | |
Add auto-margin scaling in draw_networkx_nodes function (fix for issue 3443) (#4769)
* [auto-margin scaling in draw_networkx_nodes function]
* added optional margins arg to draw_networkx_nodes
* updated draw_networkx_nodes margins docstring
* Removed unnecessary import in draw_networkx_nodes
* Update networkx/drawing/nx_pylab.py
Co-authored-by: Dan Schult <dschult@colgate.edu>
* Improve draw_networkx_nodes margins docstring
Co-authored-by: Dan Schult <dschult@colgate.edu>
* unpacking logic for *margins
* quick fix on margins logic
* Update draw_networkx_nodes margins docstring
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* draw_networkx_nodes docstring update
* draw_networkx_nodes docstring update
* Update draw_networkx_nodes margins control flow
Co-authored-by: Dan Schult <dschult@colgate.edu>
Co-authored-by: Dan Schult <dschult@colgate.edu>
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
| -rw-r--r-- | networkx/drawing/nx_pylab.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/networkx/drawing/nx_pylab.py b/networkx/drawing/nx_pylab.py index c40b9789..3d35b6b2 100644 --- a/networkx/drawing/nx_pylab.py +++ b/networkx/drawing/nx_pylab.py @@ -347,6 +347,7 @@ def draw_networkx_nodes( linewidths=None, edgecolors=None, label=None, + margins=None, ): """Draw the nodes of the graph G. @@ -402,6 +403,12 @@ def draw_networkx_nodes( label : [None | string] Label for legend + margins : float or 2-tuple, optional + Sets the padding for axis autoscaling. Increase margin to prevent + clipping for nodes that are near the edges of an image. Values should + be in the range ``[0, 1]``. See :meth:`matplotlib.axes.Axes.margins` + for details. The default is `None`, which uses the Matplotlib default. + Returns ------- matplotlib.collections.PathCollection @@ -470,6 +477,12 @@ def draw_networkx_nodes( labelleft=False, ) + if margins is not None: + if isinstance(margins, Iterable): + ax.margins(*margins) + else: + ax.margins(margins) + node_collection.set_zorder(2) return node_collection |
