In [31]:
# Import libraries 

%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import numpy as np
import mpld3
import os
from mpld3 import plugins

# If you don't have mpld3 - you can find it here: 
# Don't forget to check out more of what Jake VanderPlas is up to here:

# if all works best move on to next cell for now.  
In [32]:
#This cell is where we will get organised; 

filename = 'MyData.csv' # this is where the path to the csv you are using or (just filename if this code and the csv are in the same folder)

        #column headers in the csv can be anything, this example is based on them being "usernames", "betweenness", "pagerank", and "weighted_degree" if you want to use different headers remember to change r."your_column_header" to the correct value in the next cell. 

graph_title = '66 jihadi key actor scatter plot' # change this to the title you want at the top of your graph

Horizontal_axis_label = 'Betweenness' # change this to label your x axis

Vertical_axis_label = 'PageRank' # change this to label your y axis
In [33]:
# now we are organised, time to do something ... 
from pylab import *
rcParams['figure.figsize'] = 10, 6 # this sets the size of the plot

r = mlab.csv2rec(filename)  # this gathers the data from your csv file. 

# this is where you addd the data to your graph, using the header for each column: 

x = r.betweenness # the data do you want on your X axis - change this so it reads r."your_column_header"
y = r.pagerank #the data do you want on your Y axis - change this so it reads r."your_column_header"
un = r.usernames # this is the column used to label each point on our plot
I = r.followers # this column is currently used for colour but could be used for size of nodes, (for example if this column was 'followers' you could show which were the most followed accounts using this option)
s = # this column is for size
In [34]:
fig, ax = plt.subplots(subplot_kw=dict(axisbg='#EEEEEE')) #basic background for plot
ax.grid(color='white', linestyle='solid') # this gives you the gridlines on the plot

scatter = ax.scatter(x, y,
                     s = 5*s,

ax.set_title(graph_title, size=18)# Change this number to make title bigger or smaller

labels = [row for row in un] # this is where the labels come from to display in tooltip 
fig.plugins = [plugins.PointLabelTooltip(scatter, labels)] # magic
In []: