Skip to content

Drawing options for toDot

The look of the graphs drawn by toDot() (graphs, Bayesian networks, Markov random fields, influence diagrams, causal models, credal networks, junction trees…) is given by the keys of pyagrum.config (sections notebook, factorgraph, dynamicBN, influenceDiagram, credalnet and causal, see Configuration for pyAgrum). A pyagrum.DotOptions gives, for one drawing, what the configuration cannot: the size or the label of the graph, the color of some nodes, the width or the color of some arcs…

import pyagrum as gum
bn = gum.fastBN("A->B->C")
options = gum.DotOptions()
options.setNodeBgColor(bn.idFromName("A"), "#FF7F64")
options.setArcWidth(bn.idFromName("A"), bn.idFromName("B"), 3)
dot = bn.toDot(options)

The font color of a node is adaptive by default (black or white according to the brightness of its background color), see the keys nodeFgColor of the configuration.

What you give to the toDot(options) of a graph, a Bayesian network, a Markov random field, an influence diagram, a causal model, a credal network, a junction tree… beyond the look given by pyagrum.config (sections notebook, factorgraph, dynamicBN, influenceDiagram, credalnet and causal).

What is not given is taken from the configuration. The nodes are designated by their identifiers, the arcs by the identifiers of their tail and of their head (an undirected edge by its two ends, in any order) and the factor of a factor graph by the identifiers of its variables.

Examples

>>> import pyagrum as gum
>>> bn = pyagrum.fastBN('A->B->C')
>>> options = pyagrum.DotOptions()
>>> options.setSize('12!')
>>> options.setNodeBgColor(bn.idFromName('A'), '#FF7F64')
>>> options.setArcWidth(bn.idFromName('A'), bn.idFromName('B'), 3)
>>> dot = bn.toDot(options)
  • Returns: True if nothing was given.
  • Return type: bool
  • Returns: the label given for the graph, an empty string if none was given.
  • Return type: str
  • Returns: the layout given for the graph, an empty string if none was given.
  • Return type: str
  • Returns: the direction of the layout given for the graph, an empty string if none was given.
  • Return type: str

setArcAttribute(tail, head, key, value, verbatim=False)

Section titled “setArcAttribute(tail, head, key, value, verbatim=False)”
  • Parameters:
    • tail (int) – the id of the tail of the arc.
    • head (int) – the id of the head of the arc.
    • key (str) – the name of a graphviz attribute of the arc (letters, digits and underscores).
    • value (str) – its value.
    • verbatim (bool) – if True, the value is written as it is.
  • Return type: None
  • Parameters:
    • tail (int) – the id of the tail of the arc.
    • head (int) – the id of the head of the arc.
    • color (str) – the color of the arc.
  • Return type: None
  • Parameters:
    • tail (int) – the id of the tail of the arc.
    • head (int) – the id of the head of the arc.
    • label (str) – the text displayed next to the arc.
  • Return type: None
  • Parameters:
    • tail (int) – the id of the tail of the arc.
    • head (int) – the id of the head of the arc.
    • tooltip (str) – the text displayed when the mouse is over the arc.
  • Return type: None
  • Parameters:
    • tail (int) – the id of the tail of the arc.
    • head (int) – the id of the head of the arc.
    • width (float) – the width of the line of the arc (at least 0).
  • Raises: pyagrum.InvalidArgument – if the width is negative or not a finite number.
  • Return type: None

setFactorAttribute(variables, key, value, verbatim=False)

Section titled “setFactorAttribute(variables, key, value, verbatim=False)”
  • Parameters:
    • variables (set[int] | list[int]) – the ids of the variables of the factor (in a factor graph of a Markov random field).
    • key (str) – the name of a graphviz attribute of the factor.
    • value (str) – its value.
    • verbatim (bool) – if True, the value is written as it is.
  • Return type: None
  • Parameters:
    • variables (set[int] | list[int]) – the ids of the variables of the factor (in a factor graph of a Markov random field).
    • color (str) – the background color of the factor.
  • Return type: None
  • Parameters:
    • variables (set[int] | list[int]) – the ids of the variables of the factor (in a factor graph of a Markov random field).
    • color (str) – the font color of the factor.
  • Return type: None
  • Parameters:
    • variables (set[int] | list[int]) – the ids of the variables of the factor (in a factor graph of a Markov random field).
    • label (str) – the text displayed in the factor.
  • Return type: None
  • Parameters:
    • variables (set[int] | list[int]) – the ids of the variables of the factor (in a factor graph of a Markov random field).
    • tooltip (str) – the text displayed when the mouse is over the factor.
  • Return type: None
  • Parameters: label (str) – the label of the graph.
  • Return type: None
  • Parameters: layout (str) – the graphviz layout engine ('dot', 'neato', 'fdp'…).
  • Return type: None

setNodeAttribute(node, key, value, verbatim=False)

Section titled “setNodeAttribute(node, key, value, verbatim=False)”
  • Parameters:
    • node (int) – the id of the node.
    • key (str) – the name of a graphviz attribute of the node (letters, digits and underscores).
    • value (str) – its value.
    • verbatim (bool) – if True, the value is written as it is (with its own quotes if it needs some), for instance for an HTML label.
  • Return type: None
  • Parameters:
    • node (int) – the id of the node.
    • color (str) – the background color of the node ('#RRGGBB' or a name of color). If no font color is given for the node, the text is black or white according to the brightness of this background.
  • Return type: None
  • Parameters:
    • node (int) – the id of the node.
    • color (str) – the font color of the node ('adaptive' for black or white according to the background).
  • Return type: None
  • Parameters:
    • node (int) – the id of the node.
    • label (str) – the text displayed in the node (by default, its name).
  • Return type: None
  • Parameters:
    • node (int) – the id of the node.
    • tooltip (str) – the text displayed when the mouse is over the node.
  • Return type: None
  • Parameters: rankDir (str) – the direction of the layout: 'TB' (top to bottom) or 'LR' (left to right).
  • Return type: None
  • Parameters: size (str) – the size (for graphviz, in inches) of the graph, such as '5' or '12!' for an exact size.
  • Return type: None
  • Returns: the size given for the graph, an empty string if none was given.
  • Return type: str