- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Drawing a network graph with networkX and Matplotlib
To draw a network graph with networkx and matplotlib, plt.show() −
Set the figure size and adjust the padding between and around the subplots.
Make an object for a dataframe with the keys, from and to.
Get a graph containing an edgelist.
Draw a graph (Step 3) using draw() method with some node properties.
To display the figure, use show() method.
Example
import pandas as pd import networkx as nx from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({'from': ['A', 'B', 'C', 'A'], 'to': ['D', 'A', 'E', 'C']}) G = nx.from_pandas_edgelist(df, 'from', 'to') nx.draw(G, with_labels=True, node_size=100, alpha=1, linewidths=10) plt.show()
Output
- Related Articles
- Matplotlib – Drawing lattices and graphs with Networkx
- How to change the attributes of a networkx / matplotlib graph drawing?
- How to use an update function to animate a NetworkX graph in Matplotlib?
- Creating curved edges with NetworkX in Python3 (Matplotlib)
- Drawing a rectangle with only border in Matplotlib
- How to reshape a networkx graph in Python?
- Drawing circles on an image with Matplotlib and NumPy
- How to make multipartite graphs using networkx and Matplotlib?
- Creating a graph with date and time in axis labels with Matplotlib
- Drawing multiple figures in parallel in Python with Matplotlib
- Colouring the edges by weight in networkx (Matplotlib)
- How to draw node colormap in NetworkX/Matplotlib?
- Plot a Line Graph for Pandas Dataframe with Matplotlib?
- How to set NetworkX edge labels offset in Matplotlib?
- How can I create a stacked line graph with matplotlib?

Advertisements