#!/usr/bin/env python # coding: utf-8 # ![](logo-06.png) # #

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 # * Rating # * Cities visited # * Year(s) visited # * Comments about the trip # * If I would return again # # # Required Libraries: # > * `pandas` # * `Plotly` # * `Cufflinks` # #
# # In[4]: iplot(choromap) #








# ### Loading Required Libraries and Reading the Data into Python # In[1]: 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') # ### Adding the flavor text # This is the text that appears when hovering over a country # # * Note: Line breaks are added manually in the comment section of the csv file. # In[2]: country_df['Flavor Text'] = ("Country: " + country_df['Country'] + "
" + "My Rating: " + country_df['Rating'].map(str) + "/10
" + "Cities Visited: " + country_df['Cities Visited'] + "
" + "Year(s) Visited: " + country_df['Year Visited'] + "

" + "Comments:
" + country_df['Comments'] +"

" + "Would I Return Again?
" + country_df['Would Return?'] ) country_df.head(2) # ### Generating the Choropleth Map # In[3]: 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)