- 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
How to change the attributes of a networkx / matplotlib graph drawing?
To change the attributes of a netwrokx/matplotlib graph drawing, we can take the following steps −
Steps
Set the figure size and adjust the padding between and around the subplots.
Initialize a graph with edges, name, or graph attributes.
Add the graph's attributes. Add an edge between u and v.
Get the edge attributes from the graph.
Position the nodes with circles.
Draw the graph G with Matplotlib.
To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import networkx as nx plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True G = nx.Graph() G.add_edge(0, 1, color='r', weight=2) G.add_edge(1, 2, color='g', weight=4) G.add_edge(2, 3, color='b', weight=6) G.add_edge(3, 4, color='y', weight=3) G.add_edge(4, 0, color='m', weight=1) colors = nx.get_edge_attributes(G, 'color').values() weights = nx.get_edge_attributes(G, 'weight').values() pos = nx.circular_layout(G) nx.draw(G, pos, edge_color=colors, width=list(weights), with_labels=True, node_color='lightgreen') plt.show()
Output
It will produce the following output −
- Related Articles
- Drawing a network graph with networkX and Matplotlib
- Matplotlib – Drawing lattices and graphs with Networkx
- How to use an update function to animate a NetworkX graph in Matplotlib?
- How to reshape a networkx graph in Python?
- How to change the space between bars when drawing multiple barplots in Pandas? (Matplotlib)
- How to draw node colormap in NetworkX/Matplotlib?
- How to set NetworkX edge labels offset in Matplotlib?
- How to make multipartite graphs using networkx and Matplotlib?
- Change values on matplotlib imshow() graph axis
- How to show node name in Matplotlib graphs using networkx?
- How can one modify the outline color of a node in networkx using Matplotlib?
- Colouring the edges by weight in networkx (Matplotlib)
- How do I customize the display of edge labels using networkx in Matplotlib?
- How to remove whitespaces at the bottom of a Matplotlib graph?
- How to change the linewidth of a hatch in Matplotlib?

Advertisements