'Converts this transform graph to the graphviz_ DOT format.
Optionally saves it (requires `graphviz`_ be installed and on your path).
.. _graphviz: http://www.graphviz.org/
Parameters
priorities : bool
If `True`, show the priority values for each transform.  Otherwise,
the will not be included in the graph.
addnodes : sequence of str
Additional coordinate systems to add (this can include systems
already in the transform graph, but they will only appear once).
savefn : `None` or str
The file name to save this graph to or `None` to not save
to a file.
savelayout : str
The graphviz program to use to layout the graph (see
graphviz_ for details) or \'plain\' to just save the DOT graph
content. Ignored if ``savefn`` is `None`.
saveformat : str
The graphviz output format. (e.g. the ``-Txxx`` option for
the command line program - see graphviz docs for details).
Ignored if ``savefn`` is `None`.
color_edges : bool
Color the edges between two nodes (frames) based on the type of
transform. ``FunctionTransform``: red, ``StaticMatrixTransform``:
blue, ``DynamicMatrixTransform``: green.
Returns
dotgraph : str
A string with the DOT format graph.'

def to_dot_graph(self, priorities=True, addnodes=[], savefn=None, savelayout=u'plain', saveformat=None, color_edges=True):

    nodes = []
    for a in self._graph:
        if (a not in nodes):
            nodes.append(a)
        for b in self._graph[a]:
            if (b not in nodes):
                nodes.append(b)
    for node in addnodes:
        if (node not in nodes):
            nodes.append(node)
    nodenames = []
    invclsaliases = dict([(v, k) for (k, v) in six.iteritems(self._cached_names)])
    for n in nodes:
        if (n in invclsaliases):
            nodenames.append(u'{0}    [shape=oval    label="{0}\\n`{1}`"]'.format(n.__name__, invclsaliases[n]))
        else:
            nodenames.append((n.__name__ + u'[    shape=oval    ]'))
    edgenames = []
    for a in self._graph:
        agraph = self._graph[a]
        for b in agraph:
            transform = agraph[b]
            pri = (transform.priority if hasattr(transform, u'priority') else 1)
            color = (trans_to_color[transform.__class__] if color_edges else u'black')
            edgenames.append((a.__name__, b.__name__, pri, color))
    lines = [u'digraph    AstropyCoordinateTransformGraph    {']
    lines.append((u';    '.join(nodenames) + u';'))
    for (enm1, enm2, weights, color) in edgenames:
        labelstr_fmt = u'[    {0}    {1}    ]'
        if priorities:
            priority_part = u'label    =    "{0}"'.format(weights)
        else:
            priority_part = u''
        color_part = u'color    =    "{0}"'.format(color)
        labelstr = labelstr_fmt.format(priority_part, color_part)
        lines.append(u'{0}    ->    {1}{2};'.format(enm1, enm2, labelstr))
    lines.append(u'')
    lines.append(u'overlap=false')
    lines.append(u'}')
    dotgraph = u'\n'.join(lines)
    if (savefn is not None):
        if (savelayout == u'plain'):
            with open(savefn, u'w') as f:
                f.write(dotgraph)
        else:
            args = [savelayout]
            if (saveformat is not None):
                args.append((u'-T' + saveformat))
            proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            (stdout, stderr) = proc.communicate(dotgraph)
            if (proc.returncode != 0):
                raise IOError((u'problem    running    graphviz:    \n' + stderr))
            with open(savefn, u'w') as f:
                f.write(stdout)
    return dotgraph
