Draw a graph with NetworkX

Introduction

This article summarizes how to visualize graphs created with NetworkX, a package for creating graphs (in graph theory with nodes and edges) in Python, with Matplotlib.

Basically, it is a Japanese translation of the NetworkX reference.

Drawing a graph

There are two ways to draw a graph created with NetworkX.

  1. Use Matplotlib
  2. Use the networkx.drawing package Please note that the networkx.drawing package is not yet compatible with Python versions 3.0 and above.

If you want to draw using Matplotlib, please import Matplotlib.

from matplotlib import pyplot as plt 

To see if the imported networkx.drawing package works, try running the following code

nx.draw(G)
nx.draw_random(G)
nx.draw_circular(G)
nx.draw_spectral(G)

To show it on the display, execute the following command.

plt.show()

If you want to save the drawn graph to a file, do as follows.

nx.draw(G)
plt.savefig("path_to_fig.png ")

References

Recommended Posts

Draw a graph with NetworkX
Draw a graph with networkx
Draw a graph with Julia + PyQtGraph (2)
Draw a loose graph with matplotlib
Draw a graph with Julia + PyQtGraph (1)
Draw a graph with Julia + PyQtGraph (3)
Draw a graph with pandas + XlsxWriter
Draw a graph with PySimple GUI
Draw a graph with PyQtGraph Part 1-Drawing
Draw a flat surface with a matplotlib 3d graph
Draw a graph with Japanese labels in Jupyter
How to draw a 2-axis graph with pyplot
Draw a graph with PyQtGraph Part 3-PlotWidget settings
Draw a graph by processing with Pandas groupby
[Python] Draw a directed graph with Dash Cytoscape
Draw a graph with PyQtGraph Part 4-PlotItem settings
Draw a graph with matplotlib from a csv file
Draw a graph with PyQtGraph Part 6-Displaying a legend
Draw a graph with PyQtGraph Part 5-Increase the Y-axis
[Python] How to draw a line graph with Matplotlib
Draw a graph with PyQtGraph Part 2--Detailed plot settings
Draw a beautiful circle with numpy
Let's make a graph with python! !!
Make a nice graph with plotly
Output networkX graph with graphviz (PyGraphviz)
Easily draw a map with matplotlib.basemap
Study math with Python: Draw a sympy (scipy) graph with matplotlib
[Visualization] I want to draw a beautiful graph with Plotly
[PyQt] Display a multi-axis graph with QtChart
How to draw a graph using Matplotlib
Draw a heart in Ruby with PyCall
Draw a Mandelbrot set with Brainf * ck
Count the maximum concatenated part of a random graph with NetworkX
Create a Connecting Nearest Neighbor with NetworkX
Simply draw a graph by specifying a file
Create a graph with borders removed with matplotlib
(Matplotlib) I want to draw a graph with a size specified in pixels
How to draw a bar graph that summarizes multiple series with matplotlib
Draw a graph that can be moved around with HoloViews and Bokeh
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
Draw a graph of a quadratic function in Python
How to draw a 3D graph before optimization
Draw a "breast curved surface" in a 3D graph (1)
A memo that made a graph animated with plotly
Try to draw a life curve with python
[Python] Draw a Mickey Mouse with Turtle [Beginner]
Draw a "breast curved surface" in a 3D graph (2)
I made a random number graph with Numpy
Draw multiple photos in a graph from multiple folders
NetworkX memo (directed graph)
A4 size with python-pptx
Band graph with matplotlib
NetworkX graph generator list
Decorate with a decorator
Draw graph in python
Draw a graph in Julia ... I tried a little analysis
I tried to draw a route map with Python
Visualize railway line data as a graph with Cytoscape 2
Forcibly draw something like a flowchart with Python, matplotlib
Note that there was a version problem with networkx
[Python] How to draw a scatter plot with Matplotlib