- 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 can one modify the outline color of a node in networkx using Matplotlib?
To modify the outline color of a node in networkx, we can use set_edgecolor() method.
Steps
- Create a Pandas dataframe with from and to keys.
- Return a graph from Pandas DataFrame containing an edge list.
- Get the position of the nodes.
- Draw the nodes of the graph using draw_networkx_nodes().
- Set the outline color of the nodes using set_edgecolor().
- To display the figure, use show() method.
Example
from networkx import * import matplotlib.pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.00, 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') pos = spring_layout(G) nodes = draw_networkx_nodes(G, pos) nodes.set_edgecolor('red') plt.show()
Output
- Related Articles
- How to show node name in Matplotlib graphs using networkx?
- How to draw node colormap in NetworkX/Matplotlib?
- How do I customize the display of edge labels using networkx in Matplotlib?
- How to make multipartite graphs using networkx and Matplotlib?
- How to remove the outline of a circle marker when using pyplot.plot in Matplotlib?
- How to change the attributes of a networkx / matplotlib graph drawing?
- How to change the color of a line using radiobuttons in Matplotlib?
- How can I set the background color on specific areas of a Pyplot figure using Matplotlib?
- The outline-color Property in CSS
- How to change the face color of a plot using Matplotlib?
- How can I get the color of the last figure in Matplotlib?
- Change the outline color for histogram bars using ggplot2 in R.
- Colouring the edges by weight in networkx (Matplotlib)
- How to set NetworkX edge labels offset in Matplotlib?
- Set the color of the outline with CSS

Advertisements