In [11]:
import plotly.graph_objs as go
import pandas as pd
from plotly.offline import init_notebook_mode,iplot
init_notebook_mode(connected=True)
Reading the csv file: 2014_World_Power_Consumption
In [12]:
df = pd.read_csv('2014_World_Power_Consumption')
In [13]:
df.head()
Out[13]:
Checking the head of the DataFrame.
In [14]:
df.head()
Out[14]:
Creating a Choropleth Plot of the Power Consumption for Countries using the data and layout dictionary.
In [15]:
data = dict(type='choropleth',
colorscale = 'Viridis',
reversescale = True,
locations = df['Country'],
z=df['Power Consumption KWH'],
locationmode = "country names",
text = df['Country'],
colorbar={'title': 'Power Consumption in KWH'})
In [16]:
layout = dict(title = 'Power Consumption for Countries', geo = dict(showframe = False))
In [17]:
choromap = go.Figure(data = [data],layout = layout)
iplot(choromap,validate=False)
In [18]:
df = pd.read_csv('2012_Election_Data')
Head of the DataFrame.
In [19]:
df.head()
Out[19]:
In [20]:
data = dict(type='choropleth',
colorscale = 'Portland',
locations = df['State Abv'],
z = df['Voting-Age Population (VAP)'],
locationmode = "USA-states",
text = df['State'],
colorbar = {'title': 'VAP per state'})
In [21]:
layout = dict(title = 'Voting-Age Population (VAP) per state',
geo = dict(scope='usa',showframe = False,projection = {'type':'Mercator'}))
In [22]:
choromap = go.Figure(data = [data],layout = layout)
iplot(choromap,validate=False)