Use Graphviz to Generate Graphs

Install it from https://graphviz.org/download/ and add the installation path to se PATH variable.
Then, install the library in python:

pip install graphviz

Then, you can generate graphs, example for an deterministic automaton:

from graphviz import Digraph
 
# Init Digraph object.
dfa = Digraph(comment='AFD')
 
# Init transitions.
dfa.node('q0', 'q0')
dfa.node('q1', 'q1')
dfa.node('q2', 'q2', shape='doublecircle')
 
# Transitions
dfa.edge('q0', 'q0', label='a')
dfa.edge('q0', 'q1', label='b')
dfa.edge('q1', 'q2', label='a')
dfa.edge('q1', 'q1', label='b')
dfa.edge('q2', 'q0', label='a')
dfa.edge('q2', 'q1', label='b')
 
# Hot it should look.
dfa.attr(rankdir='LR')  # horizontal
 
# Save and print
dfa.render('afd_diagram', format='png', view=True)

Result: