Skip to content

Instantly share code, notes, and snippets.

@arimitramaiti
Last active July 28, 2020 11:27
Show Gist options
  • Save arimitramaiti/baced68ac989b4eca7d5702bb647ffa1 to your computer and use it in GitHub Desktop.
Save arimitramaiti/baced68ac989b4eca7d5702bb647ffa1 to your computer and use it in GitHub Desktop.
Plot Centrality Distribution of Random Graph Model for Mumbai Local Rail Network
##Import required modules
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
import scipy.stats as stats
import math
##Read the centrality scores generated from empirical network of mumbai local rail
url = "https://raw.githubusercontent.com/arimitramaiti/datasets/master/articles/mumbai_local_centrality_scores.csv"
dataset = pd.read_csv(url, error_bad_lines=False, header=0, index_col=None)
dataset.head(4)
##Plot the comparison
fig, ax = plt.subplots(2, 2, figsize=(12, 6))
sns.distplot(dataset.degree_random.astype("int32"), hist=True, kde=False, label=["Degree Distribution"], ax=ax[0,0])
ax[0,0].legend(loc='best', shadow=True,fontsize='medium')
ax[0,0].spines['top'].set_visible(False)
ax[0,0].spines['right'].set_visible(False)
ax[0,0].set_title("Degree Centrality-Random NW Model")
ax[0,0].set_xlabel("Degree", fontsize=11, weight='bold')
sns.distplot(dataset.closeness_random, hist=True, kde=True, label=["Closeness Centrality"], ax=ax[0,1])
sns.distplot(dataset.closeness, hist=False, kde=True, label=["Empirical NW Closeness"], ax=ax[0,1])
ax[0,1].legend(loc='best', shadow=True,fontsize='medium')
ax[0,1].spines['top'].set_visible(False)
ax[0,1].spines['right'].set_visible(False)
ax[0,1].set_title("Closeness Centrality-Random NW Model")
ax[0,1].set_xlabel("Closeness", fontsize=11, weight='bold')
sns.distplot(dataset.betweenness_random, hist=True, kde=True, label=["Betweenness Centrality"], ax=ax[1,0])
sns.distplot(dataset.betweenness, hist=False, kde=True, label=["Empirical NW Betweenness"], ax=ax[1,0])
ax[1,0].legend(loc='best', shadow=True,fontsize='medium')
ax[1,0].spines['top'].set_visible(False)
ax[1,0].spines['right'].set_visible(False)
ax[1,0].set_title("Betweenness Centrality-Random NW Model")
ax[1,0].set_xlabel("Betweenness", fontsize=11, weight='bold')
sns.distplot(dataset.eigen_random, hist=False, kde=True, label=["Eigen Centrality"], ax=ax[1,1])
sns.distplot(dataset.eigen, hist=False, kde=True, label=["Empirical NW Eigen Value"], ax=ax[1,1])
ax[1,1].legend(loc='best', shadow=True,fontsize='medium')
ax[1,1].spines['top'].set_visible(False)
ax[1,1].spines['right'].set_visible(False)
ax[1,1].set_title("Eigen Value Centrality-Random NW Model")
ax[1,1].set_xlabel("Eigen", fontsize=11, weight='bold')
fig.tight_layout()
plt.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment