# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 2
#     language: python
#     name: python2
# ---

# # Graph Drawing

# NetworkX does not have strong visualization capabilities. It primarily relies upon an old, and hacked together drawing function written to utilize matplotlib. This means that matplotlib drawing is slow, non-interactive, and has many visual bugs. For example, arrows for directed graphs are particularly unpleasant.
#
# NetworkX can also use graphviz through the pygraphviz interface to read, write, and (sort of) display graphs visualized with graphviz.
#
# For these reasons, I do not recommended that NetworkX be used as a primary tool for visualization of graphs. Visualization may be removed entirely from NetworkX in the future and moved to a separate package in the 2.0 release.
#
# In general, I think it is a rare instance when visualizing a graph can provide meaningful information. While many graph visualizations are aesthetically pleasing, they do not convey information about the graph that could be more easily discovered by analyzing the graph using different metrics. Moreover, because positional layouts can be arbitrary, they may cause people to view structure when there is none. This is is epeciall true as graphs become larger than 100 nodes.
#
# Regardless here are some things that illustrate the basics of graph drawing in NetworkX.

import networkx as nx

# This is some Jupyter magic to make the plots show up inline

# %matplotlib inline

G = nx.barbell_graph(5,2)

nx.draw(G)

nx.draw(G,with_labels=True)

pos = nx.layout.fruchterman_reingold_layout(G)

nx.draw(G,pos=pos)

nx.draw(G,pos=pos,with_labels=True)

nx.draw(G,pos=pos,with_labels=True,node_color=G.nodes())

G = nx.barabasi_albert_graph(15,1)
nx.draw(G,with_labels=True,node_color=G.nodes(),width=3)

G = nx.random_geometric_graph(50,0.2)
kcore = nx.core_number(G)
core_color = [kcore[n] for n in G.nodes()]
pos = nx.get_node_attributes(G,'pos')
size = [3.14*G.degree(n)**2 for n in G.nodes()]

nx.draw(G,node_color=core_color,lw=.5,pos=pos,node_size=size)





StarcoderdataJupyterScriptsDedupFiltered