FEV_KEGG.Drawing.Draw module

class FEV_KEGG.Drawing.Draw.NetworkxLayout[source]

Bases: enum.Enum

Enum of layout algorithms known to NetworkX.

fruchterman_reingold(k=None, pos=None, fixed=None, iterations=50, threshold=0.0001, weight='weight', scale=1, center=None, dim=2, random_state=None)

Position nodes using Fruchterman-Reingold force-directed algorithm.

Parameters:
  • G (NetworkX graph or list of nodes) – A position will be assigned to every node in G.
  • k (float (default=None)) – Optimal distance between nodes. If None the distance is set to 1/sqrt(n) where n is the number of nodes. Increase this value to move nodes farther apart.
  • pos (dict or None optional (default=None)) – Initial positions for nodes as a dictionary with node as keys and values as a coordinate list or tuple. If None, then use random initial positions.
  • fixed (list or None optional (default=None)) – Nodes to keep fixed at initial position.
  • iterations (int optional (default=50)) – Maximum number of iterations taken
  • threshold (float optional (default = 1e-4)) – Threshold for relative error in node position changes. The iteration stops if the error is below this threshold.
  • weight (string or None optional (default='weight')) – The edge attribute that holds the numerical value used for the edge weight. If None, then all edge weights are 1.
  • scale (number (default: 1)) – Scale factor for positions. Not used unless fixed is None.
  • center (array-like or None) – Coordinate pair around which to center the layout. Not used unless fixed is None.
  • dim (int) – Dimension of layout.
  • random_state (int, RandomState instance or None optional (default=None)) – Set the random state for deterministic node layouts. If int, random_state is the seed used by the random number generator, if numpy.random.RandomState instance, random_state is the random number generator, if None, the random number generator is the RandomState instance used by numpy.random.
Returns:

pos – A dictionary of positions keyed by node

Return type:

dict

Examples

>>> G = nx.path_graph(4)
>>> pos = nx.spring_layout(G)

# The same using longer but equivalent function name >>> pos = nx.fruchterman_reingold_layout(G)

kamada_kawai(dist=None, pos=None, weight='weight', scale=1, center=None, dim=2)

Position nodes using Kamada-Kawai path-length cost-function.

Parameters:
  • G (NetworkX graph or list of nodes) – A position will be assigned to every node in G.
  • dist (float (default=None)) – A two-level dictionary of optimal distances between nodes, indexed by source and destination node. If None, the distance is computed using shortest_path_length().
  • pos (dict or None optional (default=None)) – Initial positions for nodes as a dictionary with node as keys and values as a coordinate list or tuple. If None, then use circular_layout().
  • weight (string or None optional (default='weight')) – The edge attribute that holds the numerical value used for the edge weight. If None, then all edge weights are 1.
  • scale (number (default: 1)) – Scale factor for positions.
  • center (array-like or None) – Coordinate pair around which to center the layout.
  • dim (int) – Dimension of layout.
Returns:

pos – A dictionary of positions keyed by node

Return type:

dict

Examples

>>> G = nx.path_graph(4)
>>> pos = nx.kamada_kawai_layout(G)
random(center=None, dim=2, random_state=None)

Position nodes uniformly at random in the unit square.

For every node, a position is generated by choosing each of dim coordinates uniformly at random on the interval [0.0, 1.0).

NumPy (http://scipy.org) is required for this function.

Parameters:
  • G (NetworkX graph or list of nodes) – A position will be assigned to every node in G.
  • center (array-like or None) – Coordinate pair around which to center the layout.
  • dim (int) – Dimension of layout.
  • random_state (int, RandomState instance or None optional (default=None)) – Set the random state for deterministic node layouts. If int, random_state is the seed used by the random number generator, if numpy.random.RandomState instance, random_state is the random number generator, if None, the random number generator is the RandomState instance used by numpy.random.
Returns:

pos – A dictionary of positions keyed by node

Return type:

dict

Examples

>>> G = nx.lollipop_graph(4, 3)
>>> pos = nx.random_layout(G)
shell(nlist=None, scale=1, center=None, dim=2)

Position nodes in concentric circles.

Parameters:
  • G (NetworkX graph or list of nodes) – A position will be assigned to every node in G.
  • nlist (list of lists) – List of node lists for each shell.
  • scale (number (default: 1)) – Scale factor for positions.
  • center (array-like or None) – Coordinate pair around which to center the layout.
  • dim (int) – Dimension of layout, currently only dim=2 is supported.
Returns:

pos – A dictionary of positions keyed by node

Return type:

dict

Examples

>>> G = nx.path_graph(4)
>>> shells = [[0], [1, 2, 3]]
>>> pos = nx.shell_layout(G, shells)

Notes

This algorithm currently only works in two dimensions and does not try to minimize edge crossings.

spectral(weight='weight', scale=1, center=None, dim=2)

Position nodes using the eigenvectors of the graph Laplacian.

Parameters:
  • G (NetworkX graph or list of nodes) – A position will be assigned to every node in G.
  • weight (string or None optional (default='weight')) – The edge attribute that holds the numerical value used for the edge weight. If None, then all edge weights are 1.
  • scale (number (default: 1)) – Scale factor for positions.
  • center (array-like or None) – Coordinate pair around which to center the layout.
  • dim (int) – Dimension of layout.
Returns:

pos – A dictionary of positions keyed by node

Return type:

dict

Examples

>>> G = nx.path_graph(4)
>>> pos = nx.spectral_layout(G)

Notes

Directed graphs will be considered as undirected graphs when positioning the nodes.

For larger graphs (>500 nodes) this will use the SciPy sparse eigenvalue solver (ARPACK).

spring(k=None, pos=None, fixed=None, iterations=50, threshold=0.0001, weight='weight', scale=1, center=None, dim=2, random_state=None)

Position nodes using Fruchterman-Reingold force-directed algorithm.

Parameters:
  • G (NetworkX graph or list of nodes) – A position will be assigned to every node in G.
  • k (float (default=None)) – Optimal distance between nodes. If None the distance is set to 1/sqrt(n) where n is the number of nodes. Increase this value to move nodes farther apart.
  • pos (dict or None optional (default=None)) – Initial positions for nodes as a dictionary with node as keys and values as a coordinate list or tuple. If None, then use random initial positions.
  • fixed (list or None optional (default=None)) – Nodes to keep fixed at initial position.
  • iterations (int optional (default=50)) – Maximum number of iterations taken
  • threshold (float optional (default = 1e-4)) – Threshold for relative error in node position changes. The iteration stops if the error is below this threshold.
  • weight (string or None optional (default='weight')) – The edge attribute that holds the numerical value used for the edge weight. If None, then all edge weights are 1.
  • scale (number (default: 1)) – Scale factor for positions. Not used unless fixed is None.
  • center (array-like or None) – Coordinate pair around which to center the layout. Not used unless fixed is None.
  • dim (int) – Dimension of layout.
  • random_state (int, RandomState instance or None optional (default=None)) – Set the random state for deterministic node layouts. If int, random_state is the seed used by the random number generator, if numpy.random.RandomState instance, random_state is the random number generator, if None, the random number generator is the RandomState instance used by numpy.random.
Returns:

pos – A dictionary of positions keyed by node

Return type:

dict

Examples

>>> G = nx.path_graph(4)
>>> pos = nx.spring_layout(G)

# The same using longer but equivalent function name >>> pos = nx.fruchterman_reingold_layout(G)

FEV_KEGG.Drawing.Draw.toPNG(graph: FEV_KEGG.Graph.Models.CommonGraphApi, fileName: path/file, layout='neato')[source]

Draw graph and save it as PNG format in a file.

Drawing requires an algorithm to determine the best position für each node and the best path for each edge. This algorithm can be defined via layout.

Parameters:
  • graph (Models.CommonGraphApi) – The graph to be drawn.
  • fileName (str) – Path and name of the file, the extension ‘.png’ is automatically applied. The path is relative to the current working directory!
  • layout (str, optional) – A layout algorithm known to pygraphviz.
Raises:
  • ImportError – If pygraphviz is not installed. This is an optional dependency and not installed via pip by deault! PyGraphviz needs Graphviz to function, which is not a python program and has to be installed manually by you!
  • NotImplementedError – If graph is not of a NetworkX type.
FEV_KEGG.Drawing.Draw.toWindow(graph: FEV_KEGG.Graph.Models.CommonGraphApi, layout: FEV_KEGG.Drawing.Draw.NetworkxLayout)[source]

Draw graph and display it in a window.

Drawing requires an algorithm to determine the best position für each node and the best path for each edge. This algorithm can be defined via layout.

Parameters:
Raises:
  • ImportError – If matplotlib is not installed. This is an optional dependency and not installed via pip by deault! Matplotlib needs a working backend to function, which is not a python program and has to be installed manually by you! For a list of backends, see Matplotlib’s website.
  • NotImplementedError – If graph is not of a NetworkX type.