Last active
December 29, 2023 22:36
-
-
Save banditkings/d7c5c2d1ce42b5cf324b62258dfd515b to your computer and use it in GitHub Desktop.
Draw a DAG with `graphviz` python api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple example of using graphviz to draw DAGs while working in a jupyter notebook environment | |
import graphviz as gr | |
# Simple DAG with a confounder | |
h = gr.Digraph('Simple DAG with confounder') | |
h.edge('Treatment', 'Outcome') | |
h.edge('Confounder', 'Treatment') | |
h.edge('Confounder', 'Outcome') | |
display(h) | |
# Regression Example | |
g = gr.Digraph('Regression with subgraph') | |
g.edge('alpha', 'mu') | |
g.edge('beta', 'mu') | |
#subgraph name must begin with 'cluster' | |
with g.subgraph(name='cluster') as c: | |
c.attr(label='N', labeljust='r', labelloc='b') | |
c.edges([('mu', 'y'), ('sigma', 'y')]) | |
c.node('y', label='obs', style='filled') | |
display(g) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
'hello world' examples of using the python
graphviz
library to create simple DAGs while in jupyter notebook.