- 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
Creating curved edges with NetworkX in Python3 (Matplotlib)
To create curved edges with NetworkX in Python3, we can use connectionstyle="arc3, rad=0.4".
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Initialize a graph with edges, name, and graph attributes.
- Add nodes to the created graph.
- Add edges from one node to another.
- Draw the graph G with Matplotlib, with connectionstyle="arc3, rad=0.4".
- To display the figure, use show() method.
Example
import matplotlib.pylab as plt import networkx as nx plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True G = nx.DiGraph() pos = nx.spring_layout(G) G.add_nodes_from([1, 2, 3, 4]) G.add_edges_from([(1, 2), (2, 4), (2, 3), (4, 1)]) nx.draw(G, with_labels=True, connectionstyle="arc3,rad=0.4") plt.show()
Output
Advertisements