I am working on the representation of flight routes between different airports and wish to represent them using a networkx plot.
The input data is a dataframe, example:
from, to, airline, trip_number
Paris, New York, Air France, AF001
Paris, Munich, Air France, AF002
Paris, New York, Air France, AF003
Toronto, Paris, Air Canada, AC001
Toronto, Munich, Air Canada, AC002
Munich, New York, Lufthansa, LF001
Franfort, Los Angeles, Lufthansa, LF002
Francfort, Paris, Lufthansa, LF003
Paris, Francfort, Lufthansa, LF004
Paris, Francfort, Air France, AF004
Paris, Francfort, Air Berlin, AB001
I manage to get a network representation, but i am missing two items:
- label of each node
- increase the size of the connecting line when the number of trips increase (example: small for Toronto Paris as there is 1 trip, wide for Paris Francfort as there are 3 trips
Current minimum code, df being the dataframe:
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
from nxviz.plots import CircosPlot
G = nx.from_pandas_edgelist(df, 'from', 'to')
nx.draw(G, node_size=5, node_color='red')
plt.show()
Thanks for the hand