<commit_before>#!/usr/bin/env python
"""
An example showing how to use the interface to the pygraphviz
AGraph class to convert to and from graphviz. 

Also see the pygraphviz documentation and examples at
https://networkx.lanl.gov/pygraphviz/

"""
__author__ = """<NAME> (<EMAIL>)"""
#    Copyright (C) 2006-2008 by 
#    <NAME> <<EMAIL>>
#    <NAME> <<EMAIL>>
#    <NAME> <<EMAIL>>
#    All rights reserved.
#    BSD license.

import networkx as nx

# networkx graph
X=nx.Graph()
# ad edges with red color
X.add_edge(1,2,{'color':'red'})
X.add_edge(2,3,{'color':'red'})
# add nodes 3 and 4
X.add_node(3)
X.add_node(4)

# convert to a graphviz graph, 
# use edge attributes from Graph edge data
# no node attributes, or default graph, node, or edge attributes
A=nx.to_agraph(X)   

# set some default attributes for pygraphviz
default_attributes={'graph':{},'node':{},'edge':{}}
default_attributes['graph']['label']='pygraphviz graph'
default_attributes['node']['shape']='circle'

# set some node attributes
node_attributes={}
node_attributes[3]={'color':'green','shape':'box'}

# convert to AGraph, override any attributes with those on given command line 
A1=nx.to_agraph(X,
             graph_attr=default_attributes,
             node_attr=node_attributes,
             )

# write to dot file
A1.write('k5_attributes.dot')   

# convert back to networkx Graph with attributes on edges and
# default attributes as dictionary data
X=nx.from_agraph(A1)
print "edges"
print X.edges(data=True)
print "default attributes"
print X.graph_attr
print "node attributes"
print X.node_attr<commit_msg>Update pygraphviz examples. Refs #384<commit_after>#!/usr/bin/env python
"""
An example showing how to use the interface to the pygraphviz
AGraph class to convert to and from graphviz. 

Also see the pygraphviz documentation and examples at
https://networkx.lanl.gov/pygraphviz/

"""
__author__ = """<NAME> (<EMAIL>)"""
#    Copyright (C) 2006-2010 by 
#    <NAME> <<EMAIL>>
#    <NAME> <<EMAIL>>
#    <NAME> <<EMAIL>>
#    All rights reserved.
#    BSD license.

import networkx as nx

# networkx graph
G=nx.Graph()
# ad edges with red color
G.add_edge(1,2,color='red')
G.add_edge(2,3,color='red')
# add nodes 3 and 4
G.add_node(3)
G.add_node(4)

# convert to a graphviz agraph 
A=nx.to_agraph(G)   

# write to dot file
A.write('k5_attributes.dot')   

# convert back to networkx Graph with attributes on edges and
# default attributes as dictionary data
X=nx.from_agraph(A)
print("edges")
print(X.edges(data=True))
print("default graph attributes")
print(X.graph)
print("node node attributes")
print(X.node)
{'fraction_non_alphanumeric': 0.1337432744043044, 'fraction_numerical': 0.015757109915449655, 'mean_word_length': 4.561965811965812, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3860452', 'n_tokens_mistral': 909, 'n_tokens_neox': 879, 'n_words': 267}