File: raw_dot.rst

package info (click to toggle)
python-graphviz 0.20.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,188 kB
  • sloc: python: 4,098; makefile: 13
file content (48 lines) | stat: -rw-r--r-- 1,508 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Using raw DOT
-------------

To render a ready-made DOT_ source code string
(instead of assembling one with the higher-level interface
of :class:`.Graph` or :class:`.Digraph`),
create a :class:`graphviz.Source` object holding your DOT string:

.. doctest::

    >>> import graphviz  # doctest: +NO_EXE

    >>> src = graphviz.Source('digraph "the holy hand grenade" { rankdir=LR; 1 -> 2 -> 3 -> lob }')

    >>> src  #doctest: +ELLIPSIS
    <graphviz.sources.Source object at 0x...>

Use the :meth:`~.Source.render` method to save and render it:

.. doctest::

    >>> doctest_mark_exe()  # skip this line

    >>> src.render('doctest-output/holy-grenade.gv').replace('\\', '/')
    'doctest-output/holy-grenade.gv.pdf'

.. doctest::

    >>> doctest_mark_exe()  # skip this line

    >>> src.render('doctest-output/holy-grenade.gv', view=True).replace('\\', '/')  # doctest: +SKIP
    'doctest-output/holy-grenade.gv.pdf'

.. image:: _static/holy-grenade.svg
    :align: center

.. hint::

    Apart from lacking editing methods, :class:`.Source` objects have the same basic API
    as the higher-level :class:`.Graph` and :class:`.Digraph` objects
    (e.g. :meth:`~.Source.save`, :meth:`~.Source.render`, :meth:`~.Source.view`,
    :meth:`~.Source.pipe` methods,
    :attr:`~.Source.engine` and :attr:`~.Source.format` attributes,
    Jupyter notebook :meth:`~.Source._repr_mimebundle_`, etc.
    See :class:`API docs <.Source>`).


.. include:: _links.rst