{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "![](logo-06.png)\n", "\n", "

A Choropleth Visualization of my Travels Throughout the Years

\n", "\n", "

\n", "\n", "Goal of the Notebook:\n", "\n", "> 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:\n", "> * Country name\n", "* Rating\n", "* Cities visited\n", "* Year(s) visited\n", "* Comments about the trip\n", "* If I would return again\n", "\n", "\n", "Required Libraries:\n", "> * `pandas`\n", "* `Plotly`\n", "* `Cufflinks`\n", "\n", "
\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "hide_input": true }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "data": [ { "colorbar": { "title": "My Personal Rating" }, "colorscale": "Viridis", "hoverinfo": "text", "locations": [ "USA", "CAN", "THA", "KHM", "IDN", "ARE", "GBR", "SWE", "FIN", "EST", "RUS", "AUS", "DNK", "NLD", "DEU" ], "text": [ "Country: United States of America
My Rating: 7/10
Cities Visited: Chicago, New York, Los Angeles, Philidelphia
Year(s) Visited: 2007, 2013, 2017

Comments:
Mixture of the smartest and dumbest people in the world

Would I Return Again?
Yes", "Country: Canada
My Rating: 9/10
Cities Visited: Ottawa, Montreal, Toronto, Gatineau
Year(s) Visited: 2005-2009, 2011-2018

Comments:
America's friendly frozen neighbours

Would I Return Again?
Yes", "Country: Thailand
My Rating: 8/10
Cities Visited: Bangkok, Chiang Mai, Koh Samui
Year(s) Visited: 2014, 2016-2017

Comments:
Beautiful country whose economy seems
to revolve around sex tourism. Must visit for any
Muay Thai fan!

Would I Return Again?
No", "Country: Cambodia
My Rating: 4/10
Cities Visited: Siem Reap
Year(s) Visited: 2017

Comments:
Take your iconic photo at Angkor Wat
and run. The scars from the Khmer Rouge
genocide are deep, giving it a
depressing vibe.

Would I Return Again?
No", "Country: Indonesia
My Rating: 10/10
Cities Visited: Bali, Ubud
Year(s) Visited: 2017

Comments:
My favorite travel destination bar none!
The food is spectacular, the people are beyond generous,
and being surrounded by the jungle is pure bliss.
Watching the Blue Flames was unforgettable

Would I Return Again?
Yes", "Country: United Arab Emirates
My Rating: 8/10
Cities Visited: Abu Dhabi, Dubai, Sharjah, Al-Ain, Ras Al-Khaimah
Year(s) Visited: 1992-2005

Comments:
Land of extravagance, luxury, and pseudo-wealth.
Summer heat & humid are unbearable at times, but
well worth the visit

Would I Return Again?
Yes", "Country: United Kingdom
My Rating: 5/10
Cities Visited: London
Year(s) Visited: 2008, 2009

Comments:
There are just too many people in
London.

Would I Return Again?
No", "Country: Sweden
My Rating: 9/10
Cities Visited: Stockholm
Year(s) Visited: 2009

Comments:
Such a beautiful city with even more
beautiful people. 2 days was definitely
not enough

Would I Return Again?
Yes", "Country: Finland
My Rating: 7/10
Cities Visited: Helsinki
Year(s) Visited: 2009

Comments:
It's basically Sweden's less
attractive sibling.

Would I Return Again?
No", "Country: Estonia
My Rating: 8/10
Cities Visited: Talinn
Year(s) Visited: 2009

Comments:
Beautiful old architecture with cobblestone
walkways is a great alternative to the big city life.

Would I Return Again?
No", "Country: Russian Federation
My Rating: 7/10
Cities Visited: St. Petersburg
Year(s) Visited: 2009

Comments:
The vibe was somewhat ominous, but surprisingly
safe. Expect to encounter at least three weddings
each day if you're visiting in the summertime

Would I Return Again?
Yes", "Country: Australia
My Rating: 6/10
Cities Visited: Melbourne, Sydney, Gold Coast
Year(s) Visited: 2010

Comments:
Home of brash and slightly racist people
with great accents. Footy (Australian rules football) is
still a mystery to me.

Would I Return Again?
Yes", "Country: Denmark
My Rating: 7/10
Cities Visited: Copenhagen
Year(s) Visited: 2009

Comments:
Home of the iconic Little Mermaid sculpture. This isn’t your run of the mill wanna-be Ariel

Would I Return Again?
Yes", "Country: Netherlands
My Rating: 8/10
Cities Visited: Amsterdam
Year(s) Visited: 2009

Comments:
Completed the \"daytime\" tourist
attractions including the Anne
Frank House, but the depravity of
Amsterdam is yet to be explored!

Would I Return Again?
Yes", "Country: Germany
My Rating: 5/10
Cities Visited: Warnemünde, Rostock
Year(s) Visited: 2009

Comments:
I got the feeling that life outside
Berlin isn't all that great, but
I'd love to party it up there one day!

Would I Return Again?
Yes" ], "type": "choropleth", "z": [ 7, 9, 8, 4, 10, 8, 5, 9, 7, 8, 7, 6, 7, 8, 5 ] } ], "layout": { "autosize": false, "geo": { "countrycolor": "grey", "lakecolor": "rgb(255, 255, 255)", "projection": { "type": "orthographic" }, "showcountries": true, "showframe": false, "showlakes": true }, "height": 800, "title": "My Travels Over the Years", "width": 900 } }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "iplot(choromap)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "








" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Loading Required Libraries and Reading the Data into Python" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import pandas as pd\n", "import plotly.plotly as py\n", "import plotly.graph_objs as go \n", "import cufflinks as cf\n", "\n", "from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot\n", "\n", "init_notebook_mode(connected=True)\n", "cf.go_offline()\n", "\n", "country_df = pd.read_csv(\"Countries.csv\", encoding='ISO-8859-1')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Adding the flavor text\n", "This is the text that appears when hovering over a country\n", "\n", "* Note: Line breaks are added manually in the comment section of the csv file." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
CodeCountryRatingWould Return?Cities VisitedYear VisitedCommentsFlavor Text
0USAUnited States of America7YesChicago, New York, Los Angeles, Philidelphia2007, 2013, 2017Mixture of the smartest and dumbest people in ...<b>Country:</b> United States of America<br><b...
1CANCanada9YesOttawa, Montreal, Toronto, Gatineau2005-2009, 2011-2018America's friendly frozen neighbours<b>Country:</b> Canada<br><b>My Rating:</b> 9/...
\n", "
" ], "text/plain": [ " Code Country Rating Would Return? \\\n", "0 USA United States of America 7 Yes \n", "1 CAN Canada 9 Yes \n", "\n", " Cities Visited Year Visited \\\n", "0 Chicago, New York, Los Angeles, Philidelphia 2007, 2013, 2017 \n", "1 Ottawa, Montreal, Toronto, Gatineau 2005-2009, 2011-2018 \n", "\n", " Comments \\\n", "0 Mixture of the smartest and dumbest people in ... \n", "1 America's friendly frozen neighbours \n", "\n", " Flavor Text \n", "0 Country: United States of America
Country: Canada
My Rating: 9/... " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "country_df['Flavor Text'] = (\"Country: \" + country_df['Country'] + \"
\" +\n", " \"My Rating: \" + country_df['Rating'].map(str) + \"/10
\" +\n", " \"Cities Visited: \" + country_df['Cities Visited'] + \"
\" +\n", " \"Year(s) Visited: \" + country_df['Year Visited'] + \"

\" +\n", " \"Comments:
\" + country_df['Comments'] +\"

\" +\n", " \"Would I Return Again?
\" + country_df['Would Return?']\n", " )\n", "\n", "country_df.head(2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Generating the Choropleth Map" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "data = dict(type='choropleth',\n", " locations = country_df['Code'],\n", " z = country_df['Rating'],\n", " text = country_df['Flavor Text'],\n", " colorbar = {'title': 'My Personal Rating'},\n", " colorscale= 'Viridis',\n", " hoverinfo = \"text\" \n", ")\n", "\n", "layout = dict(\n", " title = 'My Travels Over the Years',\n", " autosize=False,\n", " width=900,\n", " height=800,\n", " geo = dict(\n", " showframe = False,\n", " projection = {'type':'orthographic'},\n", " showlakes = True,\n", " lakecolor = 'rgb(255, 255, 255)',\n", " showcountries=True,\n", " countrycolor = \"grey\" \n", " )\n", ")\n", "\n", "choromap = go.Figure(data = [data],layout = layout)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.3" } }, "nbformat": 4, "nbformat_minor": 2 }