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 gumbn = 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.
class pyagrum.DotOptions
Section titled “class pyagrum.DotOptions”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)empty()
Section titled “empty()”- Returns: True if nothing was given.
- Return type:
bool
label()
Section titled “label()”- Returns: the label given for the graph, an empty string if none was given.
- Return type:
str
layout()
Section titled “layout()”- Returns: the layout given for the graph, an empty string if none was given.
- Return type:
str
rankDir()
Section titled “rankDir()”- 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.
- tail (
- Return type:
None
setArcColor(tail, head, color)
Section titled “setArcColor(tail, head, color)”- 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.
- tail (
- Return type:
None
setArcLabel(tail, head, label)
Section titled “setArcLabel(tail, head, label)”- 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.
- tail (
- Return type:
None
setArcTooltip(tail, head, tooltip)
Section titled “setArcTooltip(tail, head, tooltip)”- 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.
- tail (
- Return type:
None
setArcWidth(tail, head, width)
Section titled “setArcWidth(tail, head, width)”- 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).
- tail (
- 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.
- variables (
- Return type:
None
setFactorBgColor(variables, color)
Section titled “setFactorBgColor(variables, color)”- 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.
- variables (
- Return type:
None
setFactorFgColor(variables, color)
Section titled “setFactorFgColor(variables, color)”- 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.
- variables (
- Return type:
None
setFactorLabel(variables, label)
Section titled “setFactorLabel(variables, label)”- 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.
- variables (
- Return type:
None
setFactorTooltip(variables, tooltip)
Section titled “setFactorTooltip(variables, tooltip)”- 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.
- variables (
- Return type:
None
setLabel(label)
Section titled “setLabel(label)”- Parameters:
label (
str) – the label of the graph. - Return type:
None
setLayout(layout)
Section titled “setLayout(layout)”- 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.
- node (
- Return type:
None
setNodeBgColor(node, color)
Section titled “setNodeBgColor(node, color)”- 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.
- node (
- Return type:
None
setNodeFgColor(node, color)
Section titled “setNodeFgColor(node, color)”- 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).
- node (
- Return type:
None
setNodeLabel(node, label)
Section titled “setNodeLabel(node, label)”- Parameters:
- node (
int) – the id of the node. - label (
str) – the text displayed in the node (by default, its name).
- node (
- Return type:
None
setNodeTooltip(node, tooltip)
Section titled “setNodeTooltip(node, tooltip)”- Parameters:
- node (
int) – the id of the node. - tooltip (
str) – the text displayed when the mouse is over the node.
- node (
- Return type:
None
setRankDir(rankDir)
Section titled “setRankDir(rankDir)”- Parameters:
rankDir (
str) – the direction of the layout:'TB'(top to bottom) or'LR'(left to right). - Return type:
None
setSize(size)
Section titled “setSize(size)”- Parameters:
size (
str) – the size (for graphviz, in inches) of the graph, such as'5'or'12!'for an exact size. - Return type:
None
size()
Section titled “size()”- Returns: the size given for the graph, an empty string if none was given.
- Return type:
str