Skip to content

Commit de02fcc

Browse files
committed
Use numpy style docstring
1 parent 472544b commit de02fcc

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

mathicsscript/format.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,11 @@ def hierarchy_pos(
6767
G, root=None, width=1.0, vert_gap=0.2, vert_loc=0, leaf_vs_root_factor=0.5
6868
):
6969

70-
"""From EoN (Epidemics on Networks): a fast, flexible Python package
71-
for simulation, analytic approximation, and analysis of epidemics
72-
on networks
73-
https://joss.theoj.org/papers/10.21105/joss.01731
74-
75-
If the graph is a tree this will return the positions to plot this in a
76-
hierarchical layout.
70+
"""Position nodes in tree layout. The root is at the top.
7771
7872
Based on Joel's answer at https://stackoverflow.com/a/29597209/2966723,
7973
but with some modifications.
8074
81-
We include this because it may be useful for plotting transmission trees,
82-
and there is currently no networkx equivalent (though it may be coming soon).
83-
8475
There are two basic approaches we think of to allocate the horizontal
8576
location of a node.
8677
@@ -97,26 +88,51 @@ def hierarchy_pos(
9788
or top down approaches. ``0`` gives pure bottom up, while 1 gives pure top
9889
down.
9990
91+
From EoN (Epidemics on Networks): a fast, flexible Python package
92+
for simulation, analytic approximation, and analysis of epidemics
93+
on networks
94+
https://joss.theoj.org/papers/10.21105/joss.01731
10095
10196
:Arguments:
10297
103-
**G** the graph (must be a tree)
98+
Parameters
99+
----------
100+
G : NetworkX graph or list of nodes
101+
A position will be assigned to every node in G.
102+
The graph must be a tree.
103+
104+
root : the root node of the tree
104105
105-
**root** the root node of the tree
106106
- if the tree is directed and this is not given, the root will be found and used
107107
- if the tree is directed and this is given, then the positions will be
108108
just for the descendants of this node.
109109
- if the tree is undirected and not given, then a random choice will be used.
110110
111-
**width** horizontal space allocated for this branch - avoids overlap with other branches
111+
width : horizontal space allocated for this branch - avoids overlap with other branches
112+
113+
vert_gap : gap between levels of hierarchy
114+
115+
vert_loc : vertical location of root
116+
117+
leaf_vs_root_factor : used in calculating the _x_ coordinate of a leaf
118+
119+
xcenter : horizontal location of root
112120
113-
**vert_gap** gap between levels of hierarchy
121+
Examples
122+
--------
123+
>>> G = nx.binomial_tree(3)
124+
>>> nx.draw(G, pos=nx.hierarchy_layout(G, root=0))
114125
115-
**vert_loc** vertical location of root
126+
As the number of nodes gets large, the node size and node labels
127+
may need to be adjusted. The following shows how the minimum
128+
separation between nodes can be used to adjust node sizes.
116129
117-
**leaf_vs_root_factor**
130+
>>> G = nx.full_rary_tree(2, 127)
131+
>>> pos, min_sep = nx.hierarchy_layout_with_min_sep(G, root=0)
132+
>>> nx.draw(G, pos=pos, node_size=min_sep * 1500)
118133
119-
xcenter: horizontal location of root
134+
Also see the NetworkX drawing examples at
135+
https://networkx.org/documentation/latest/auto_examples/index.html
120136
121137
"""
122138
if not nx.is_tree(G):

0 commit comments

Comments
 (0)