xflr6/graphviz

Graphs not displaying inline in jupyter when created in a function

davechurchill opened this issue · 2 comments

dot = Digraph()
dot.edge('1', '2')
dot.edge('2', '3')
dot

Inside a jupyter notebook, the above code creates a graph and displays it inline in the notebook just fine, however when I put this exact same code inside a function and then call the function, nothing is displayed:

def graph_me():
  dot = Digraph()
  dot.edge('1', '2')
  dot.edge('2', '3')
  dot
graph_me()

Anyone know why this might be happening? Seems very odd

xflr6 commented

In the first example, the last bare dot line will show the vaue of that variable in the Jupyter REPL (which in this case renders the graph and displays it's SVG representation in Jupyter).

In the second example, the value displayed by the last line is the return value of the your function, which is None. Change the last line of the function to return dot.

Oh wow I'm dumb. Thanks for the reply :)