A Choropleth Visualization of my Travels Throughout the Years
Goal of the Notebook:
To gain experience with Plotly visualization software by generating an interactive Choropleth World Map. The colors of each country represents my overall rating of the trip or trips. Hovering over each country will show a variety of notes about each trip, including:
- Country name
Required Libraries:
pandas
Plotly
Cufflinks
iplot(choromap)
import pandas as pd
import plotly.plotly as py
import plotly.graph_objs as go
import cufflinks as cf
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)
cf.go_offline()
country_df = pd.read_csv("Countries.csv", encoding='ISO-8859-1')
This is the text that appears when hovering over a country
country_df['Flavor Text'] = ("<b>Country:</b> " + country_df['Country'] + "<br>" +
"<b>My Rating:</b> " + country_df['Rating'].map(str) + "/10<br>" +
"<b>Cities Visited:</b> " + country_df['Cities Visited'] + "<br>" +
"<b>Year(s) Visited:</b> " + country_df['Year Visited'] + "<br><br>" +
"<b>Comments:</b><br>" + country_df['Comments'] +"<br><br>" +
"<b>Would I Return Again?</b> <br>" + country_df['Would Return?']
)
country_df.head(2)
Code | Country | Rating | Would Return? | Cities Visited | Year Visited | Comments | Flavor Text | |
---|---|---|---|---|---|---|---|---|
0 | USA | United States of America | 7 | Yes | Chicago, New York, Los Angeles, Philidelphia | 2007, 2013, 2017 | Mixture of the smartest and dumbest people in ... | <b>Country:</b> United States of America<br><b... |
1 | CAN | Canada | 9 | Yes | Ottawa, Montreal, Toronto, Gatineau | 2005-2009, 2011-2018 | America's friendly frozen neighbours | <b>Country:</b> Canada<br><b>My Rating:</b> 9/... |
data = dict(type='choropleth',
locations = country_df['Code'],
z = country_df['Rating'],
text = country_df['Flavor Text'],
colorbar = {'title': 'My Personal Rating'},
colorscale= 'Viridis',
hoverinfo = "text"
)
layout = dict(
title = 'My Travels Over the Years',
autosize=False,
width=900,
height=800,
geo = dict(
showframe = False,
projection = {'type':'orthographic'},
showlakes = True,
lakecolor = 'rgb(255, 255, 255)',
showcountries=True,
countrycolor = "grey"
)
)
choromap = go.Figure(data = [data],layout = layout)