This example is probably the most basic network chart you can realise.
A network chart is constituted by nodes. These nodes are interconnected by edges. So a basic format is a data frame where each line describes a connection.
Here we construct a data frame with 4 lines, describing the 4 connections of this plot! So if you have a csv file with your connections, load it and you are ready to visualise it!
Next step: customise the chart parameters!
# libraries import pandas as pd import numpy as np import networkx as nx import matplotlib.pyplot as plt # Build a dataframe with 4 connections df = pd.DataFrame({ 'from':['A', 'B', 'C','A'], 'to':['D', 'A', 'E','C']}) df # Build your graph G=nx.from_pandas_dataframe(df, 'from', 'to') # Plot it nx.draw(G, with_labels=True) plt.show()
I get this error:
AttributeError: module ‘networkx’ has no attribute ‘from_pandas_dataframe’
instead of from_pandas_dataframe use from_pandas_edgelist
https://stackoverflow.com/questions/49223057/attributeerror-module-networkx-has-no-attribute-from-pandas-dataframe
G=nx.from_pandas_dataframe(df, ‘from’, ‘to’)
throws an error because it has been deprecated. Instead, use “nx.from_pandas_edgelist(df, ‘from’, ‘to’)
when i tried to run this code i am getting error:
AttributeError: module ‘networkx’ has no attribute ‘from_pandas_dataframe’
G=nx.from_pandas_edgelist(df, ‘from’, ‘to’)
Do you know how to add arrows for the edge with the data?
I tried a lot of ways but do not know why they do not show up…
Do you know how to add arrows for the edges?