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.
- 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 bypyagrum.config(sectionsnotebook,factorgraph,dynamicBN,influenceDiagram,credalnetandcausal).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.
Example
import pyagrum as gum
bn = gum.fastBN("A->B->C")
options = gum.DotOptions()
options.setSize("12!")
options.setNodeBgColor(bn.idFromName("A"), "#FF7F64")
options.setArcWidth(bn.idFromName("A"), bn.idFromName("B"), 3)
dot = bn.toDot(options)
print("\n".join(line.strip() for line in dot.splitlines() if '"A"' in line or line.strip().startswith("graph [")))
# graph [bgcolor="transparent", size="12!", rankdir="TB", layout="dot"];
# "A" [tooltip="(0) A", fillcolor="#FF7F64", fontcolor="black"];
# "A" -> "B" [fontsize="10", tooltip="0 → 1", penwidth="3"];
Methods