Drawing Documentation

This page contains the Drawing Package documentation.

The bidirectional Module

The graphviz Module

Functions for drawing and displaying graphs using Graphviz layouts.

cmpy.drawing.graphviz.cleaned_node(n)

Makes clean representation of node, removing quotes.

cmpy.drawing.graphviz.draw_graphviz(G, filename=None, format=None, prefix=None, suffix=None, layout='dot', args='', labelstyle=1, join=True, show=True, env=None)

Draws the graph G using the specified layout algorithm.

Parameters:

G : GeneratorAtEdges

The machine to convert into a PyGraphviz object.

filename : str, None

The name of the file to save the image to. If None, save to a temporary file. File formats are inferred from the extension of the filename. If the format parameter is provided, it overwrites any inferred value.

format : str

An output format. Note that not all may be available on every system depending on how Graphviz was built. If no filename is provided and no format is specified, then we write a ‘png’ image. Other values for format are:

‘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’

prefix : str | None

If filename is None, we save to a temporary file. The value of prefix will appear at after ‘cmpy_‘ but before random string and file extension. If None, then no prefix is inserted.

suffix : str | None

If filename is None, we save to a temporary file. The value of suffix will appear at after the prefix and random string but before the file extension. If None, then no suffix is used.

layout : str

The graphviz layout program. It must exist in your PATH. Common values are:

‘neato’,’dot’,’twopi’,’circo’,’fdp’,’nop’, ‘wc’,’acyclic’,’gvpr’, ‘gvcolor’,’ccomps’,’sccmap’,’tred’

args : str

Additional arguments to pass to the Graphviz layout program.

labelstyle : int, None

A specification of the label style. Default option is 0. Certain machine classes ignore the provided value and use a hard-coded value so that the machine is displayed properly. Valid options:

0 No labels are drawn. 1 Full CMPy label in “input | probability | output” format.

If input or output is None, then we adjust accordingly.

2 Probability is removed from the label. 3 Only output is shown.

join : bool

If True, then an attempt is made to join the characters of the output (or input) symbols. That is, output=(‘1’,‘0’) would be displayed as ‘10’.

show : bool

If True, then the image is displayed using the default viewer after drawing it.

Notes

If this function is called in succession to quickly, it doesn’t seem to work. So you might want to sleep for a second between calls.

cmpy.drawing.graphviz.get_labelstyle(labelstyle)
cmpy.drawing.graphviz.graphviz_escaped(s)

Returns s properly escaped for a Graphviz string.

Parameters:

s : str

The string to be escaped for Graphviz.

Returns:

ges : str

The Graphviz escaped string. Use as: ‘ “%s” ‘ % (ges,)

cmpy.drawing.graphviz.to_dot(G, out=None, fancy=True, labelstyle=1, join=True)

Converts G to the DOT format.

Certain machines ignore the value of labelstyle and use a hardcoded value for proper display.

Parameters:

G : machine

The machine to convert to the Graphviz DOT format.

out : str | file object | None

If a string, it specifies where the dot file will be written. If a file object (or anything supporting a write method), then it is assumed to already be opened with mode=”w+”. If None, then we do not write to output.

fancy : bool

If True then we spice up the dot file a bit. If False, then the representation will be very basic.

labelstyle : int

A specification of the label style. Valid options:

0 No labels are drawn. 1 Full CMPy label in “input | probability | output” format.

If input or output is None, then we adjust accordingly.

2 Probability is removed from the label. 3 Only output is shown.

join : bool

If True, then an attempt is made to join the characters of the output (or input) symbols. That is, output=(‘1’,‘0’) would be displayed as ‘10’.

Returns:

dot : str

The graph represented in the Graphviz DOT format.

cmpy.drawing.graphviz.to_dot__BaseMachine(G, out, fancy)

Converts BaseMachines to the DOT format.

See the docstring for to_dot().

cmpy.drawing.graphviz.to_dot__MealyHMM(G, out, fancy, labelstyle, join)

Converts MealyHMMs to the DOT format.

See the docstring for to_dot().

cmpy.drawing.graphviz.to_dot__MooreHMM(G, out, fancy, labelstyle, join)

Converts MealyHMMs to the DOT format.

See the docstring for to_dot().

cmpy.drawing.graphviz.to_dot__postcommon(G, out)
cmpy.drawing.graphviz.to_dot__precommon(G, out, fancy)
cmpy.drawing.graphviz.write_attrs(out, attrs)

The suso Module