pygraphviz 学习笔记
个人认为python第三方库中 graphviz比 pygraphviz好,以下是之前学习pygraphviz的笔记:
G.add_path(nlist)
按nlist增加路径
G.clear() Remove all nodes, edges, and attributes from the graph.
G.degree(nbunch=None, with_labels=False)
Return the degree of nodes given in nbunch container. 这里的degree指点的连接数量。
Using optional with_labels=True returns a dictionary keyed by node with value set to the degree.
degree_iter(nbunch=None, indeg=True, outdeg=True)
Return an iterator over the degree of the nodes given in nbunch container.
Returns pairs of (node,degree).
delete_edge(u, v=None, key=None)
Remove edge between nodes u and v from the graph.
With optional key argument will only remove an edge matching (u,v,key).
delete_edges_from(ebunch)
Remove edges from ebunch (a container of edges).
delete_node(n)
Remove the single node n.
Attempting to remove a node that isn’t in the graph will produce an error.
delete_subgraph(name) Remove subgraph with given name.
property directed G.directed Return True if graph is directed or False if not.
draw(path=None, format=None, prog=None, args=‘’)
Output graph to path in specified format.
An attempt will be made to guess the output format based on the file extension of path. If that fails, then the format parameter will be used.
Note, if path is a file object returned by a call to os.fdopen(), then the method for discovering the
format will not work. In such cases, one should explicitly set the format parameter; otherwise, it will default to ‘dot’.
If path is None, the result is returned as a Bytes object.
Formats (not all may be available on every system depending on how Graphviz was built)
‘canon’, ‘cmap’, ‘cmapx’, ‘cmapx_np’, ‘dia’, ‘dot’, ‘fig’, ‘gd’, ‘gd2’, ‘gif’, ‘hpgl’, ‘imap’,
‘imap_np’, ‘ismap’, ‘jpe’, ‘jpeg’, ‘jpg’, ‘mif’, ‘mp’, ‘pcl’, ‘pdf’, ‘pic’, ‘plain’, ‘plain-ext’,
‘png’, ‘ps’, ‘ps2’, ‘svg’, ‘svgz’, ‘vml’, ‘vmlz’, ‘vrml’, ‘vtx’, ‘wbmp’, ‘xdot’, ‘xlib’
If prog is not specified and the graph has positions (see layout()) then no additional graph positioning will be performed.
Optional prog=[‘neato’|’dot’|’twopi’|’circo’|’fdp’|’nop’] will use specified graphviz layout method.
adjacent adj.相邻; 邻近的; 与…毗连的;
[例句]The house adjacent to ours is under repairs. 与我家相邻的房子正在修缮。
from_string(string)
Load a graph from a string in dot format.
Overwrites any existing graph.
To make a new graph from a string use
get_edge(u, v, key=None) Return an edge object (Edge) corresponding to edge (u,v).
get_node(n) Return a node object (Node) corresponding to node n.
get_subgraph(name) Return existing subgraph with specified name or None if it doesn’t exist.
has_edge(u, v=None, key=None) Return True an edge u-v is in the graph or False if not.
has_neighbor(u, v, key=None) Return True if u has an edge to v or False if not.
has_node(n) Return True if n is in the graph or False if not.
in_degree(nbunch=None, with_labels=False) 入度数
Return the in-degree of nodes given in nbunch container.
Using optional with_labels=True returns a dictionary keyed by node with value set to the degree.
in_degree_iter(nbunch=None)
Return an iterator over the in-degree of the nodes given in nbunch container.
Returns pairs of (node,degree).
in_edges(nbunch=None, keys=False)
Return list of in edges in the graph. If the optional nbunch (container of nodes) only in edges
adjacent to nodes in nbunch will be returned.
in_edges_iter(nbunch=None, keys=False)
Return iterator over out edges in the graph.
If the optional nbunch (container of nodes) only out edges adjacent to nodes in nbunch will be returned.
Note: modifying the graph structure while iterating over edges may produce unpredictable results. Use in_edges() as an alternative.
in_neighbors(n) Return list of predecessor nodes of n.
is_directed() Return True if graph is directed or False if not.
is_strict() Return True if graph is strict or False if not.Strict graphs do not allow parallel edges or self loops.
is_undirected() Return True if graph is undirected or False if not.
iterdegree(nbunch=None, indeg=True, outdeg=True) Return an iterator over the degree of the nodes given in nbunch container.Returns pairs of (node,degree).
iteredges(nbunch=None, keys=False)
Return iterator over edges in the graph.
If the optional nbunch (container of nodes) only edges adjacent to nodes in nbunch will be returned.
Note: modifying the graph structure while iterating over edges may produce unpredictable results. Use edges() as an alternative.
iterindegree(nbunch=None)
Return an iterator over the in-degree of the nodes given in nbunch container.
Returns pairs of (node,degree).
iterinedges(nbunch=None, keys=False)
Return iterator over out edges in the graph.
If the optional nbunch (container of nodes) only out edges adjacent to nodes in nbunch will be returned.
Note: modifying the