Interactive Maps

Mouse over the maps for interactive information

In [1]:
import plotly.graph_objs as go
from plotly.offline import init_notebook_mode,iplot
init_notebook_mode(connected=True)

Import pandas and read the csv file: 2014_World_Power_Consumption

In [2]:
import pandas as pd
In [3]:
df = pd.read_csv('2014_World_Power_Consumption')

Check the header of the DataFrame.

In [4]:
df.head()

Referencing the lecture notes, create a Choropleth Plot of the Power Consumption for Countries using the data and layout dictionary.

In [5]:
data = dict(type = 'choropleth',
            locations = df['Country'],
            locationmode = "country names",
            colorscale= 'Portland',
            text= df['Text'],
            z=df['Power Consumption KWH'],
            colorbar = {'title':'KWH'})

layout = dict(
    title = '2014 World Power Consumption',
    geo = dict(
        showframe = False,
        projection = {'type':'Mercator'}
    )
)
In [6]:
choromap = go.Figure(data = [data],layout = layout)
iplot(choromap,validate=False)

USA Choropleth

Import the 2012_Election_Data csv file using pandas.

In [7]:
edata2012 = pd.read_csv('2012_Election_Data')

Check the header of the DataFrame.

In [8]:
edata2012.head()
Out[8]:

Plot the Voting-Age Population (VAP) per state, with additional information of felonies unable to vote in each state on mousover

In [9]:
data = dict(type = 'choropleth',
            locations = edata2012['State Abv'],
            locationmode = 'USA-states',
            colorscale= 'Reds',
            text= edata2012['Total Ineligible Felon'],
            z=edata2012['Voting-Age Population (VAP)'],
            colorbar = {'title':'VAP'})

layout = dict(
    title = '2012 Voting-Age Population with Total Ineligible Felon Mouseover',
    geo = dict(scope='usa',showlakes = True,lakecolor = 'rgb(85,173,240)')
    )
In [10]:
choromap = go.Figure(data = [data],layout = layout)
iplot(choromap,validate=False)