showing a graph

Pippo adm2303.2304 at gmail.com
Tue Apr 14 02:41:08 CEST 2015


Hi, 

I want to show the graph for this code:

import re
from Tkinter import *
import tkFileDialog
import testpattern
import networkx as nx
import matplotlib.pyplot as plt

patternresult =[]
nodes = {}
edges = {}

pattern = ['(#P\[\w*\])', '(#C\[\w*[\s\(\w\,\s\|\)]+\])',
           '(#ST\[\w*[\s\(\w\,\s\|\)]+\])', '(#A\[\w*[\s\(\w\,\s\|\)]+\])']


patternresult = testpattern.patternfinder()

G=nx.Graph()


for patres in patternresult:
    G.add_node(patres)
    if patres[1] == "P":
        first_node = patres
    

for patres in patternresult:
    
    if patres[1:3] == "ST":
        G.add_edge(first_node, patres, label="Sub-type")
    elif patres[1:2] == "C":
        G.add_edge(first_node, patres, label="Constraint_by")
    elif patres[1:3] == "A":
        G.add_edge(first_node, patres, label="Created_by")
    
#graph = G.edge()
pos = nx.shell_layout(G)
#nx.draw(G, pos)


nx.draw_networkx_nodes(G, pos, nodelist=None,
                       node_size=300, node_color='r',
                       node_shape='o', alpha=1.0,
                       cmap=None, vmin=None, vmax=None,
                       ax=None, linewidths=None)
nx.draw_networkx_edges(G, pos, edgelist=None, width=1.0, edge_color='k',
                       style='solid',alpha=None, edge_cmap=None,
                       edge_vmin=None, edge_vmax=None,ax=None, arrows=True)
nx.draw_networkx_labels(G, pos,font_size=10, font_family='sans-serif')

plt.show()

#plt.savefig("path.png")

    
But when I run the code, only a bar is shown on my desktop without showing the proper graph. Note that I checked the number of edges and the number of nodes and they are correct and this output also has been shown:
 
#C[Health]
#P[Information]
#ST[genetic information]
#C[oral | (recorded in (any form | medium))]
#C[Is created or received by]
#A[health care provider | health plan | public health authority | employer | life insurer | school | university | or health care clearinghouse]
#C[Relates to]
#C[the past, present, or future physical | mental health | condition of an individual]
#C[the provision of health care to an individual]
#C[the past, present, or future payment for the provision of health care to an individual]

I don't get any error. Just that I don't see any graph!



More information about the Python-list mailing list