- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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
Matplotlib â€“ Drawing lattices and graphs with Networkx
To draw lattices and graphs with networkx, we can take the following steps −
- Import networkx and pyplot.
- Set the figure size and adjust the padding between and around the subplots.
- Use nx.grid_2d_graph(3, 3) to get a two-dimensional grid graph. The grid graph has each node connected to its four nearest neighbors.
- Draw the graph G with Matplotlib.
- To display the figure, use show() method.
# Import networkx and pyplot import networkx as nx from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Draw the graph G = nx.grid_2d_graph(3, 3) nx.draw(G, node_size=100) plt.show()
It will produce the following output
- Related Articles
- Drawing a network graph with networkX and Matplotlib
- How to make multipartite graphs using networkx and Matplotlib?
- How to show node name in Matplotlib graphs using networkx?
- How to change the attributes of a networkx / matplotlib graph drawing?
- Creating curved edges with NetworkX in Python3 (Matplotlib)
- Drawing circles on an image with Matplotlib and NumPy
- Drawing a rectangle with only border in Matplotlib
- How to use GoJS HTML5 Canvas Library for drawing diagrams and graphs?
- 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?
- Plotting multiple line graphs using Pandas and Matplotlib
- Displaying bar graphs using Matplotlib
- How to set NetworkX edge labels offset in Matplotlib?
- Displaying horizontal bar graphs using Matplotlib