Very simple, I am trying to plot a simple state-machine like this:
I am open to any form of plotting that allows for flexibility around such a plot.
This is what I have so far:
import networkx as nx
from nxpd import draw
G = nx.MultiDiGraph(with_labels=False,rankdir='LR')
G.graph['dpi'] = 120
G.add_node(1,label=r"$\sigma_1$",shape = 'circle')
G.add_node(2,label=r"$\sigma_2$",shape = 'circle')
G.add_edge(1,1,headport='nw',tailport='sw',label='sp')
G.add_edge(2,2,headport='se',tailport='ne')
G.add_edge(1,2,label='1-sp')
draw(G, show='ipynb')
Which obviously is a far cry from what I'm trying to do.
Several things are not working:
- The
headport='nw',tailport='sw'
is doing strange things - Obviously,
r"$\sigma_2$"
is not outputting the desired tex based symbols.
How can I plot a graph that looks like the above?
Trying to achieve the same with matplotlib and networkx
import matplotlib.pyplot as plt
import networkx as nx
%matplotlib inline
G=nx.MultiDiGraph()
pos = {0:(100,100),1:(0,0)}
G.add_node(0)
G.add_node(1)
G.add_edge(0,0)
G.add_edge(0,1)
G.add_edge(1,0)
labels={}
labels[0]=r'$\sigma_1$'
labels[1]=r'$\sigma_2$'
nx.draw_networkx_labels(G,pos,labels)
plt.axis('off')
plt.show() # display
Which, for some reason, outputs a blank screen?