File: attributes.rst

package info (click to toggle)
python-graphviz 0.20.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,160 kB
  • sloc: python: 4,082; makefile: 13
file content (63 lines) | stat: -rw-r--r-- 1,556 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Attributes
----------

To directly add DOT_ ``att_stmt`` attribute statements, 
call the :meth:`~.Graph.attr` method
of the :class:`.Graph` or :class:`.Digraph` instance
with the wanted target as first argument and the attributes as keyword args.

.. hint::

    Attribute statements affect all **later** graphs, nodes, or edges
    within the same (sub-)graph.

.. doctest::

    >>> import graphviz

    >>> ni = graphviz.Graph('ni')  # doctest: +NO_EXE

    >>> ni.attr('node', shape='rarrow')
    >>> ni.node('1', 'Ni!')
    >>> ni.node('2', 'Ni!')

    >>> ni.node('3', 'Ni!', shape='egg')

    >>> ni.attr('node', shape='star')
    >>> ni.node('4', 'Ni!')
    >>> ni.node('5', 'Ni!')

If you omit the first :meth:`~.Graph.attr` argument, the method can be used
to set arbitrary attributes as key-value pairs targeting
the current (sub-)graph
(e.g. for ``rankdir``, ``label``,
or setting ``rank='same'`` within a subgraph context,
:ref:`example <rank_same.py>`):

.. doctest::

    >>> ni.attr(rankdir='LR')  # doctest: +NO_EXE

    >>> ni.edges(['12', '23', '34', '45'])

    >>> print(ni.source)  # doctest: +NORMALIZE_WHITESPACE
    graph ni {
        node [shape=rarrow]
        1 [label="Ni!"]
        2 [label="Ni!"]
        3 [label="Ni!" shape=egg]
        node [shape=star]
        4 [label="Ni!"]
        5 [label="Ni!"]
        rankdir=LR
        1 -- 2
        2 -- 3
        3 -- 4
        4 -- 5
    }

.. image:: _static/ni.svg
    :align: center


.. include:: _links.rst