networkx Graphs to Show

21 views
Skip to first unread message

Pippo

unread,
Apr 14, 2015, 8:56:06 AM4/14/15
to networkx...@googlegroups.com
Hi,

I am not sure why my code doesn't show the graph. It clearly creates the right nodes and edges but it doesn't show them. Any idea?

mport 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") 

I think the problem starts from nx.draw....

Himanshu Mishra

unread,
Apr 14, 2015, 9:03:25 AM4/14/15
to networkx...@googlegroups.com
I don't see what exactly are you trying to do here. Do you simply wish to create a graph and visualize using matplotlib ? Then you don't need to do such things.

--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discu...@googlegroups.com.
To post to this group, send email to networkx...@googlegroups.com.
Visit this group at http://groups.google.com/group/networkx-discuss.
For more options, visit https://groups.google.com/d/optout.



--
Himanshu Mishra,
First year, Mathematics and Computing,
Indian Institute of Technology Kharagpur

Pippo

unread,
Apr 14, 2015, 9:12:27 AM4/14/15
to networkx...@googlegroups.com
I want to create graph with nodes out of this:

#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]

This also shows all of the edges that are created...

{'#C[the past, present, or future payment for the provision of health care to an individual]': 1, '#A[health care provider | health plan | public health authority | employer | life insurer | school | university | or health care clearinghouse]': 0, '#C[Relates to]': 1, '#C[the past, present, or future physical | mental health | condition of an individual]': 1, '#C[Is created or received by]': 1, '#C[the provision of health care to an individual]': 1, '#C[Health]': 1, '#C[oral | (recorded in (any form | medium))]': 1, '#ST[genetic information]': 1, '#P[Information]': 8}

What should I do then?

Himanshu Mishra

unread,
Apr 14, 2015, 9:25:23 AM4/14/15
to networkx...@googlegroups.com
So you want all these informations 
#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]

to be stored in nodes?
Why don't you use the dictionary in python? It is a better option and I also don't know how a graph can help you in this.

Pippo

unread,
Apr 14, 2015, 9:33:42 AM4/14/15
to networkx...@googlegroups.com
I want to create a graph that for example links P[Information] to C[Health]

Also how can I use dictionary to save all these infos? 
Reply all
Reply to author
Forward
0 new messages