Skip to content

Commit

Permalink
Use mpl_draw in docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
mtreinish committed May 29, 2021
1 parent 2b66dcb commit cf0499b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 360 deletions.
1 change: 0 additions & 1 deletion retworkx/visualization/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ def draw_graph(graph, pos=None, arrows=True, with_labels=False, **kwds):

valid_label_kwds = {
"labels",
"edge_labels",
"font_size",
"font_color",
"font_family",
Expand Down
60 changes: 6 additions & 54 deletions src/digraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1890,14 +1890,10 @@ impl PyDiGraph {
///
/// .. jupyter-execute::
///
/// import os
/// import tempfile
///
/// from PIL import Image
/// import pydot
///
/// import retworkx
///
/// from retworkx.visualization import mpl_draw
///
/// with tempfile.NamedTemporaryFile('wt') as fd:
/// path = fd.name
Expand All @@ -1908,16 +1904,7 @@ impl PyDiGraph {
/// fd.write('2 3\n')
/// fd.flush()
/// graph = retworkx.PyDiGraph.read_edge_list(path)
///
/// # Draw graph
/// dot = pydot.graph_from_dot_data(graph.to_dot())[0]
///
/// with tempfile.TemporaryDirectory() as tmpdirname:
/// tmp_path = os.path.join(tmpdirname, 'dag.png')
/// dot.write_png(tmp_path)
/// image = Image.open(tmp_path)
/// os.remove(tmp_path)
/// image
/// mpl_draw(graph)
///
#[staticmethod]
#[text_signature = "(path, /, comment=None, deliminator=None)"]
Expand Down Expand Up @@ -2141,30 +2128,15 @@ impl PyDiGraph {
///
/// .. jupyter-execute::
///
/// import os
/// import tempfile
///
/// import pydot
/// from PIL import Image
///
/// import retworkx
/// from retworkx.visualization import mpl_draw
///
/// # Build first graph and visualize:
/// graph = retworkx.PyDiGraph()
/// node_a = graph.add_node('A')
/// node_b = graph.add_child(node_a, 'B', 'A to B')
/// node_c = graph.add_child(node_b, 'C', 'B to C')
/// dot_str = graph.to_dot(
/// lambda node: dict(
/// color='black', fillcolor='lightblue', style='filled'))
/// dot = pydot.graph_from_dot_data(dot_str)[0]
///
/// with tempfile.TemporaryDirectory() as tmpdirname:
/// tmp_path = os.path.join(tmpdirname, 'graph.png')
/// dot.write_png(tmp_path)
/// image = Image.open(tmp_path)
/// os.remove(tmp_path)
/// image
/// mpl_draw(graph, with_labels=True, labels=str, edge_labels=str)
///
/// Then build a second one:
///
Expand All @@ -2174,35 +2146,15 @@ impl PyDiGraph {
/// other_graph = retworkx.PyDiGraph()
/// node_d = other_graph.add_node('D')
/// other_graph.add_child(node_d, 'E', 'D to E')
/// dot_str = other_graph.to_dot(
/// lambda node: dict(
/// color='black', fillcolor='lightblue', style='filled'))
/// dot = pydot.graph_from_dot_data(dot_str)[0]
///
/// with tempfile.TemporaryDirectory() as tmpdirname:
/// tmp_path = os.path.join(tmpdirname, 'other_graph.png')
/// dot.write_png(tmp_path)
/// image = Image.open(tmp_path)
/// os.remove(tmp_path)
/// image
/// mpl_draw(other_graph, with_labels=True, labels=str, edge_labels=str)
///
/// Finally compose the ``other_graph`` onto ``graph``
///
/// .. jupyter-execute::
///
/// node_map = {node_b: (node_d, 'B to D')}
/// graph.compose(other_graph, node_map)
/// dot_str = graph.to_dot(
/// lambda node: dict(
/// color='black', fillcolor='lightblue', style='filled'))
/// dot = pydot.graph_from_dot_data(dot_str)[0]
///
/// with tempfile.TemporaryDirectory() as tmpdirname:
/// tmp_path = os.path.join(tmpdirname, 'combined_graph.png')
/// dot.write_png(tmp_path)
/// image = Image.open(tmp_path)
/// os.remove(tmp_path)
/// image
/// mpl_draw(graph, with_labels=True, labels=str, edge_labels=str)
///
#[text_signature = "(self, other, node_map, /, node_map_func=None, edge_map_func=None)"]
pub fn compose(
Expand Down
Loading

0 comments on commit cf0499b

Please sign in to comment.