From cfc1b98e048be4917d1142c0610ee9884b90323c Mon Sep 17 00:00:00 2001 From: Priyatharsan Rajasekar Date: Fri, 1 Mar 2019 11:21:04 -0500 Subject: [PATCH 1/6] update bubble and choropleth maps --- .../bubble-maps/2015-06-30-bubble-maps.html | 130 +++++++---- .../python/maps/bubble-maps/bubble-maps.ipynb | 86 ++++--- .../2015-06-30-Choropleth_maps.html | 210 +++++++++++------- .../choropleth-maps/Choropleth_maps.ipynb | 141 +++++++----- 4 files changed, 350 insertions(+), 217 deletions(-) diff --git a/_posts/python/maps/bubble-maps/2015-06-30-bubble-maps.html b/_posts/python/maps/bubble-maps/2015-06-30-bubble-maps.html index be9bbb626788..18a912365058 100644 --- a/_posts/python/maps/bubble-maps/2015-06-30-bubble-maps.html +++ b/_posts/python/maps/bubble-maps/2015-06-30-bubble-maps.html @@ -4,20 +4,19 @@ name: Bubble Maps has_thumbnail: true thumbnail: thumbnail/bubble-map.jpg -layout: user-guide -language: python title: Python Bubble Maps | Plotly -display_as: maps has_thumbnail: true +language: python page_type: example_index +display_as: maps order: 3 +layout: user-guide --- {% raw %}
-
-
+
-

New to Plotly?¶

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer. +

New to Plotly?

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!

@@ -25,10 +24,51 @@

New to Plotly?
+
+
+

Version Check

Plotly's python package is updated frequently. Run pip install plotly --upgrade to use the latest version.

+ +
+

+
+
+
In [2]:
+
+
import plotly
+plotly.__version__
+
+ +
+
+
+ +
+
+ + +
+ +
Out[2]:
+ + + + +
+
'3.6.0'
+
+ +
+ +
+
+ +
+
+
-

United States Bubble Map¶

Note about sizeref:

+

United States Bubble Map

Note about sizeref:

To scale the bubble size, use the attribute sizeref. We recommend using the following formula to calculate a sizeref value:

sizeref = 2. * max(array of size values) / (desired maximum marker size ** 2)

Note that setting sizeref to a value greater than $1$, decreases the rendered marker sizes, while setting sizeref to less than $1$, increases the rendered marker sizes.

@@ -39,12 +79,13 @@

United States Bubble Map @@ -118,22 +158,21 @@

United States Bubble Map
-
In [1]:
+
In [9]:
-
import plotly.plotly as py
-import plotly.graph_objs as go
+
import plotly.plotly as py
+import plotly.graph_objs as go
 
-import pandas as pd
+import pandas as pd
 
 df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_ebola.csv')
 df.head()
@@ -156,7 +195,7 @@ 

Ebola Cases in West Africa) ) -cases[0]['text'] = df[ df['Month'] == 9 ]['Value'].map('{:.0f}'.format).astype(str)+' '+\ +cases[0]['text'] = df[ df['Month'] == 9 ]['Value'].map('{:.0f}'.format).astype(str)+' '+\ df[ df['Month'] == 9 ]['Country'] cases[0]['mode'] = 'markers+text' cases[0]['textposition'] = 'bottom center' @@ -168,8 +207,8 @@

Ebola Cases in West Africaz = df[ df['Month'] == 9 ]['Value'], text = df[ df['Month'] == 9 ]['Country'], colorscale = [[0,'rgb(0, 0, 0)'],[1,'rgb(0, 0, 0)']], - autocolorscale = False, - showscale = False, + autocolorscale = False, + showscale = False, geo = 'geo2' ), go.Scattergeo( @@ -177,7 +216,7 @@

Ebola Cases in West Africalat = [7.1881], text = ['Africa'], mode = 'text', - showlegend = False, + showlegend = False, geo = 'geo2' ) ] @@ -189,9 +228,9 @@

Ebola Cases in West Africageo = dict( resolution = 50, scope = 'africa', - showframe = False, - showcoastlines = True, - showland = True, + showframe = False, + showcoastlines = True, + showland = True, landcolor = "rgb(229, 229, 229)", countrycolor = "rgb(255, 255, 255)" , coastlinecolor = "rgb(255, 255, 255)", @@ -207,10 +246,10 @@

Ebola Cases in West Africa), geo2 = dict( scope = 'africa', - showframe = False, - showland = True, + showframe = False, + showland = True, landcolor = "rgb(229, 229, 229)", - showcountries = False, + showcountries = False, domain = dict( x = [ 0, 0.6 ], y = [ 0, 0.6 ] @@ -223,10 +262,10 @@

Ebola Cases in West Africa) fig = go.Figure(layout=layout, data=cases+inset) -py.iplot(fig, validate=False, filename='West Africa Ebola cases 2014') +py.iplot(fig, filename='West Africa Ebola cases 2014')

-
+
@@ -236,12 +275,12 @@

Ebola Cases in West Africa -
Out[1]:
+
Out[9]:
- +

@@ -251,10 +290,9 @@

Ebola Cases in West Africa
-
-
+
diff --git a/_posts/python/maps/bubble-maps/bubble-maps.ipynb b/_posts/python/maps/bubble-maps/bubble-maps.ipynb index 397f3bd629ae..e9abd3bef243 100644 --- a/_posts/python/maps/bubble-maps/bubble-maps.ipynb +++ b/_posts/python/maps/bubble-maps/bubble-maps.ipynb @@ -10,6 +10,35 @@ "
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Version Check\n", + "Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'3.6.0'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly\n", + "plotly.__version__" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -29,25 +58,26 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 1, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.plotly as py\n", + "import plotly.graph_objs as go\n", "\n", "import pandas as pd\n", "\n", @@ -63,8 +93,7 @@ "for i in range(len(limits)):\n", " lim = limits[i]\n", " df_sub = df[lim[0]:lim[1]]\n", - " city = dict(\n", - " type = 'scattergeo',\n", + " city = go.Scattergeo(\n", " locationmode = 'USA-states',\n", " lon = df_sub['lon'],\n", " lat = df_sub['lat'],\n", @@ -79,7 +108,7 @@ " name = '{0} - {1}'.format(lim[0],lim[1]) )\n", " cities.append(city)\n", "\n", - "layout = dict(\n", + "layout = go.Layout(\n", " title = '2014 US city populations
(Click legend to toggle traces)',\n", " showlegend = True,\n", " geo = dict(\n", @@ -91,11 +120,11 @@ " countrywidth=1,\n", " subunitcolor=\"rgb(255, 255, 255)\",\n", " countrycolor=\"rgb(255, 255, 255)\"\n", - " ),\n", + " )\n", " )\n", "\n", - "fig = dict(data=cities, layout=layout)\n", - "py.iplot(fig, validate=False, filename='d3-bubble-map-populations')" + "fig = go.Figure(data=cities, layout=layout)\n", + "py.iplot(fig, filename='d3-bubble-map-populations')" ] }, { @@ -107,19 +136,19 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 1, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -218,7 +247,7 @@ ")\n", "\n", "fig = go.Figure(layout=layout, data=cases+inset)\n", - "py.iplot(fig, validate=False, filename='West Africa Ebola cases 2014')" + "py.iplot(fig, filename='West Africa Ebola cases 2014')" ] }, { @@ -231,7 +260,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -263,27 +292,28 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-req-build-s5ETWe\n", + " Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-7gmj7xbp\n", "Building wheels for collected packages: publisher\n", - " Running setup.py bdist_wheel for publisher ... \u001b[?25ldone\n", - "\u001b[?25h Stored in directory: /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-ephem-wheel-cache-muSfgQ/wheels/99/3e/a0/fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + " Running setup.py bdist_wheel for publisher: started\n", + " Running setup.py bdist_wheel for publisher: finished with status 'done'\n", + " Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-a2n74gbm\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", "Successfully built publisher\n", "Installing collected packages: publisher\n", - " Found existing installation: publisher 0.11\n", - " Uninstalling publisher-0.11:\n", - " Successfully uninstalled publisher-0.11\n", - "Successfully installed publisher-0.11\n" + " Found existing installation: publisher 0.13\n", + " Uninstalling publisher-0.13:\n", + " Successfully uninstalled publisher-0.13\n", + "Successfully installed publisher-0.13\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning:\n", + "C:\\Anaconda\\Anaconda3\\lib\\site-packages\\IPython\\nbconvert.py:13: ShimWarning:\n", "\n", "The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n", "\n", - "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning:\n", + "C:\\Anaconda\\Anaconda3\\lib\\site-packages\\publisher\\publisher.py:53: UserWarning:\n", "\n", "Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", "\n" @@ -319,21 +349,21 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.12" + "pygments_lexer": "ipython3", + "version": "3.7.1" } }, "nbformat": 4, diff --git a/_posts/python/maps/choropleth-maps/2015-06-30-Choropleth_maps.html b/_posts/python/maps/choropleth-maps/2015-06-30-Choropleth_maps.html index 80c69b9db240..86f19be6b3a4 100644 --- a/_posts/python/maps/choropleth-maps/2015-06-30-Choropleth_maps.html +++ b/_posts/python/maps/choropleth-maps/2015-06-30-Choropleth_maps.html @@ -4,21 +4,20 @@ name: Choropleth Maps has_thumbnail: true thumbnail: thumbnail/choropleth.jpg -layout: user-guide -language: python title: Python Choropleth Maps | Plotly -display_as: maps has_thumbnail: true -ipynb: ~notebook_demo/55 +language: python +display_as: maps order: 1 +ipynb: ~notebook_demo/55 +layout: user-guide page_type: u-guide --- {% raw %}
-
-
+
-

New to Plotly?¶

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer. +

New to Plotly?

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!

@@ -26,20 +25,63 @@

New to Plotly?
+
+
+

Version Check

Plotly's python package is updated frequently. Run pip install plotly --upgrade to use the latest version.

+ +
+

+
+
+
In [1]:
+
+
import plotly
+plotly.__version__
+
+ +
+
+
+ +
+
+ + +
+ +
Out[1]:
+ + + + +
+
'3.6.1'
+
+ +
+ +
+
+ +
+
+
-

United States Choropleth Map¶

+

United States Choropleth Map

@@ -109,61 +150,65 @@

United States Choropleth Map
-
-
+
-

World Choropleth Map¶

+

World Choropleth Map

-
In [2]:
+
In [3]:
-
import plotly.plotly as py
-import pandas as pd
+
import plotly.plotly as py
+import pandas as pd
 
 df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_world_gdp_with_codes.csv')
 
-data = [ dict(
-        type = 'choropleth',
+data = [ go.Choropleth(
         locations = df['CODE'],
         z = df['GDP (BILLIONS)'],
         text = df['COUNTRY'],
         colorscale = [[0,"rgb(5, 10, 172)"],[0.35,"rgb(40, 60, 190)"],[0.5,"rgb(70, 100, 245)"],\
             [0.6,"rgb(90, 120, 245)"],[0.7,"rgb(106, 137, 247)"],[1,"rgb(220, 220, 220)"]],
-        autocolorscale = False,
-        reversescale = True,
+        autocolorscale = False,
+        reversescale = True,
         marker = dict(
             line = dict (
                 color = 'rgb(180,180,180)',
                 width = 0.5
             ) ),
         colorbar = dict(
-            autotick = False,
             tickprefix = '$',
             title = 'GDP<br>Billions US$'),
       ) ]
 
-layout = dict(
-    title = '2014 Global GDP<br>Source:\
-            <a href="https://www.cia.gov/library/publications/the-world-factbook/fields/2195.html">\
-            CIA World Factbook</a>',
+layout = go.Layout(
+    title = '2014 Global GDP',
     geo = dict(
-        showframe = False,
-        showcoastlines = False,
+        showframe = False,
+        showcoastlines = False,
         projection = dict(
-            type = 'Mercator'
+            type = 'equirectangular'
         )
-    )
+    ),
+    annotations=[dict(
+        x=0.55,
+        y=0.1,
+        xref='paper',
+        yref='paper',
+        text='Source: <a href="https://www.cia.gov/library/publications/the-world-factbook/fields/2195.html">\
+            CIA World Factbook</a>',
+        showarrow=False
+    )]
 )
 
-fig = dict( data=data, layout=layout )
-py.iplot( fig, validate=False, filename='d3-world-map' )
+fig = go.Figure( data=data, layout=layout )
+py.iplot(fig, filename='d3-world-map' )
 
-
+
@@ -173,12 +218,12 @@

World Choropleth Map -
Out[2]:
+
Out[3]:
- +

@@ -188,22 +233,21 @@

World Choropleth Map
-
-
+
-

Choropleth Inset Map¶

+

Choropleth Inset Map

-
In [3]:
+
In [4]:
-
import plotly.plotly as py
-import plotly.graph_objs as go
+
import plotly.plotly as py
+import plotly.graph_objs as go
 
-import pandas as pd
+import pandas as pd
 df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_ebola.csv')
 df.head()
 
@@ -224,7 +268,7 @@ 

Choropleth Inset Map), ) ) -cases[0]['text'] = df[ df['Month'] == 9 ]['Value'].map('{:.0f}'.format).astype(str)+' '+\ +cases[0]['text'] = df[ df['Month'] == 9 ]['Value'].map('{:.0f}'.format).astype(str)+' '+\ df[ df['Month'] == 9 ]['Country'] cases[0]['mode'] = 'markers+text' cases[0]['textposition'] = 'bottom center' @@ -236,8 +280,8 @@

Choropleth Inset Mapz = df[ df['Month'] == 9 ]['Value'], text = df[ df['Month'] == 9 ]['Country'], colorscale = [[0,'rgb(0, 0, 0)'],[1,'rgb(0, 0, 0)']], - autocolorscale = False, - showscale = False, + autocolorscale = False, + showscale = False, geo = 'geo2' ), go.Scattergeo( @@ -245,7 +289,7 @@

Choropleth Inset Maplat = [7.1881], text = ['Africa'], mode = 'text', - showlegend = False, + showlegend = False, geo = 'geo2' ) ] @@ -257,14 +301,14 @@

Choropleth Inset Mapgeo = dict( resolution = 50, scope = 'africa', - showframe = False, - showcoastlines = True, - showland = True, + showframe = False, + showcoastlines = True, + showland = True, landcolor = "rgb(229, 229, 229)", countrycolor = "rgb(255, 255, 255)" , coastlinecolor = "rgb(255, 255, 255)", projection = dict( - type = 'Mercator' + type = 'equirectangular' ), lonaxis = dict( range= [ -15.0, -5.0 ] ), lataxis = dict( range= [ 0.0, 12.0 ] ), @@ -275,10 +319,10 @@

Choropleth Inset Map), geo2 = dict( scope = 'africa', - showframe = False, - showland = True, + showframe = False, + showland = True, landcolor = "rgb(229, 229, 229)", - showcountries = False, + showcountries = False, domain = dict( x = [ 0, 0.6 ], y = [ 0, 0.6 ] @@ -291,10 +335,10 @@

Choropleth Inset Map) fig = go.Figure(layout=layout, data=cases+inset) -py.iplot(fig, validate=False, filename='West Africa Ebola cases 2014') +py.iplot(fig, filename='West Africa Ebola cases 2014')

-
+
@@ -304,12 +348,12 @@

Choropleth Inset Map -
Out[3]:
+
Out[4]:
- +

@@ -319,24 +363,23 @@

Choropleth Inset Map
-
-
+
-

Full County Choropleths¶

For the full county choropleth doc page checkout https://plot.ly/python/county-choropleth/

+

Full County Choropleths

For the full county choropleth doc page checkout https://plot.ly/python/county-choropleth/

-
In [2]:
+
In [6]:
-
import plotly.plotly as py
-import plotly.figure_factory as ff
+
import plotly.plotly as py
+import plotly.figure_factory as ff
 
-import numpy as np
-import pandas as pd
+import numpy as np
+import pandas as pd
 
 df_sample = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/laucnty16.csv')
 df_sample['State FIPS Code'] = df_sample['State FIPS Code'].apply(lambda x: str(x).zfill(2))
@@ -353,15 +396,15 @@ 

Full County Choroplethsfig = ff.create_choropleth( fips=fips, values=values, scope=['usa'], binning_endpoints=endpts, colorscale=colorscale, - show_state_data=False, - show_hover=True, centroid_marker={'opacity': 0}, + show_state_data=False, + show_hover=True, centroid_marker={'opacity': 0}, asp=2.9, title='USA by Unemployment %', legend_title='% unemployed' ) py.iplot(fig, filename='choropleth_full_usa')

-
+
@@ -371,7 +414,7 @@

Full County Choropleths -
+
@@ -397,10 +440,9 @@

Full County Choropleths
-
-
+
-

Reference¶

See https://plot.ly/python/reference/#choropleth for more information and chart attribute options!

+

Reference

See https://plot.ly/python/reference/#choropleth for more information and chart attribute options!

diff --git a/_posts/python/maps/choropleth-maps/Choropleth_maps.ipynb b/_posts/python/maps/choropleth-maps/Choropleth_maps.ipynb index 8b5984765123..27eee6bac867 100644 --- a/_posts/python/maps/choropleth-maps/Choropleth_maps.ipynb +++ b/_posts/python/maps/choropleth-maps/Choropleth_maps.ipynb @@ -14,30 +14,61 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#### United States Choropleth Map" + "#### Version Check\n", + "Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'3.6.1'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly\n", + "plotly.__version__" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### United States Choropleth Map" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 1, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.plotly as py\n", + "import plotly.graph_objs as go\n", + "\n", "import pandas as pd\n", "\n", "df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv')\n", @@ -53,8 +84,7 @@ " 'Fruits '+df['total fruits']+' Veggies ' + df['total veggies']+'
'+\\\n", " 'Wheat '+df['wheat']+' Corn '+df['corn']\n", "\n", - "data = [ dict(\n", - " type='choropleth',\n", + "data = [ go.Choropleth(\n", " colorscale = scl,\n", " autocolorscale = False,\n", " locations = df['code'],\n", @@ -70,7 +100,7 @@ " title = \"Millions USD\")\n", " ) ]\n", "\n", - "layout = dict(\n", + "layout = go.Layout(\n", " title = '2011 US Agriculture Exports by State
(Hover for breakdown)',\n", " geo = dict(\n", " scope='usa',\n", @@ -79,8 +109,8 @@ " lakecolor = 'rgb(255, 255, 255)'),\n", " )\n", " \n", - "fig = dict( data=data, layout=layout )\n", - "py.iplot( fig, filename='d3-cloropleth-map' )" + "fig = go.Figure( data=data, layout=layout )\n", + "py.iplot(fig, filename='d3-cloropleth-map' )" ] }, { @@ -92,19 +122,19 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -115,8 +145,7 @@ "\n", "df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_world_gdp_with_codes.csv')\n", "\n", - "data = [ dict(\n", - " type = 'choropleth',\n", + "data = [ go.Choropleth(\n", " locations = df['CODE'],\n", " z = df['GDP (BILLIONS)'],\n", " text = df['COUNTRY'],\n", @@ -130,26 +159,32 @@ " width = 0.5\n", " ) ),\n", " colorbar = dict(\n", - " autotick = False,\n", " tickprefix = '$',\n", " title = 'GDP
Billions US$'),\n", " ) ]\n", "\n", - "layout = dict(\n", - " title = '2014 Global GDP
Source:\\\n", - " \\\n", - " CIA World Factbook',\n", + "layout = go.Layout(\n", + " title = '2014 Global GDP',\n", " geo = dict(\n", " showframe = False,\n", " showcoastlines = False,\n", " projection = dict(\n", - " type = 'Mercator'\n", + " type = 'equirectangular'\n", " )\n", - " )\n", + " ),\n", + " annotations=[dict(\n", + " x=0.55,\n", + " y=0.1,\n", + " xref='paper',\n", + " yref='paper',\n", + " text='Source: \\\n", + " CIA World Factbook',\n", + " showarrow=False\n", + " )]\n", ")\n", "\n", - "fig = dict( data=data, layout=layout )\n", - "py.iplot( fig, validate=False, filename='d3-world-map' )" + "fig = go.Figure( data=data, layout=layout )\n", + "py.iplot(fig, filename='d3-world-map' )" ] }, { @@ -161,19 +196,19 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 3, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -243,7 +278,7 @@ " countrycolor = \"rgb(255, 255, 255)\" ,\n", " coastlinecolor = \"rgb(255, 255, 255)\",\n", " projection = dict(\n", - " type = 'Mercator'\n", + " type = 'equirectangular'\n", " ),\n", " lonaxis = dict( range= [ -15.0, -5.0 ] ),\n", " lataxis = dict( range= [ 0.0, 12.0 ] ),\n", @@ -270,7 +305,7 @@ ")\n", "\n", "fig = go.Figure(layout=layout, data=cases+inset)\n", - "py.iplot(fig, validate=False, filename='West Africa Ebola cases 2014')" + "py.iplot(fig, filename='West Africa Ebola cases 2014')" ] }, { @@ -283,7 +318,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -296,13 +331,13 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 2, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -347,7 +382,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -379,27 +414,17 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-Nylcl7-build\n", + " Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-c7dlx5_3\n", + "Building wheels for collected packages: publisher\n", + " Running setup.py bdist_wheel for publisher: started\n", + " Running setup.py bdist_wheel for publisher: finished with status 'done'\n", + " Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-ng_5reyj\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + "Successfully built publisher\n", "Installing collected packages: publisher\n", - " Found existing installation: publisher 0.11\n", - " Uninstalling publisher-0.11:\n", - " Successfully uninstalled publisher-0.11\n", - " Running setup.py install for publisher ... \u001b[?25ldone\n", - "\u001b[?25hSuccessfully installed publisher-0.11\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning:\n", - "\n", - "The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n", - "\n", - "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning:\n", - "\n", - "Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", - "\n" + " Found existing installation: publisher 0.13\n", + " Uninstalling publisher-0.13:\n", + " Successfully uninstalled publisher-0.13\n", + "Successfully installed publisher-0.13\n" ] } ], @@ -424,30 +449,28 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.12" + "pygments_lexer": "ipython3", + "version": "3.7.1" } }, "nbformat": 4, From 2197b969bd226012fba6de37a38dd9b501b2d464 Mon Sep 17 00:00:00 2001 From: Priyatharsan Rajasekar Date: Fri, 1 Mar 2019 12:17:47 -0500 Subject: [PATCH 2/6] updated line-on-maps --- .../2015-06-30-lines_on_maps.html | 343 ++++++++++-------- .../maps/lines-on-maps/lines_on_maps.ipynb | 329 +++++++++-------- 2 files changed, 367 insertions(+), 305 deletions(-) diff --git a/_posts/python/maps/lines-on-maps/2015-06-30-lines_on_maps.html b/_posts/python/maps/lines-on-maps/2015-06-30-lines_on_maps.html index 0f0134558188..e36836b97eda 100644 --- a/_posts/python/maps/lines-on-maps/2015-06-30-lines_on_maps.html +++ b/_posts/python/maps/lines-on-maps/2015-06-30-lines_on_maps.html @@ -4,22 +4,21 @@ name: Lines on maps | plotly has_thumbnail: true thumbnail: thumbnail/flight-paths.jpg -layout: user-guide -name: Lines on Maps -language: python title: Lines on maps | plotly -display_as: maps +name: Lines on Maps has_thumbnail: true +language: python page_type: example_index +display_as: maps order: 4 ipynb: ~notebook_demo/58 +layout: user-guide --- {% raw %}
-
-
+
-

New to Plotly?¶

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer. +

New to Plotly?

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!

@@ -27,20 +26,63 @@

New to Plotly?
+
+
+

Version Check

Plotly's python package is updated frequently. Run pip install plotly --upgrade to use the latest version.

+ +
+

+
+
+
In [1]:
+
+
import plotly
+plotly.__version__
+
+ +
+
+
+ +
+
+ + +
+ +
Out[1]:
+ + + + +
+
'3.6.1'
+
+ +
+ +
+
+ +
+
+
-

US Flight Paths Map¶

+

US Flight Paths Map

-
In [1]:
+
In [2]:
-
import plotly.plotly as py
-import pandas as pd
+
import plotly.plotly as py
+import plotly.graph_objs as go
+
+import pandas as pd
 
 df_airports = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_us_airport_traffic.csv')
 df_airports.head()
@@ -48,57 +90,57 @@ 

US Flight Paths Mapdf_flight_paths = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv') df_flight_paths.head() -airports = [ dict( - type = 'scattergeo', - locationmode = 'USA-states', - lon = df_airports['long'], - lat = df_airports['lat'], - hoverinfo = 'text', - text = df_airports['airport'], - mode = 'markers', - marker = dict( - size=2, - color='rgb(255, 0, 0)', - line = dict( - width=3, - color='rgba(68, 68, 68, 0)' - ) - ))] - +airports = [go.Scattergeo( + locationmode = 'USA-states', + lon = df_airports['long'], + lat = df_airports['lat'], + hoverinfo = 'text', + text = df_airports['airport'], + mode = 'markers', + marker = dict( + size = 2, + color = 'rgb(255, 0, 0)', + line = dict( + width = 3, + color = 'rgba(68, 68, 68, 0)' + ) + ))] + flight_paths = [] -for i in range( len( df_flight_paths ) ): +for i in range(len(df_flight_paths)): flight_paths.append( - dict( - type = 'scattergeo', + go.Scattergeo( locationmode = 'USA-states', - lon = [ df_flight_paths['start_lon'][i], df_flight_paths['end_lon'][i] ], - lat = [ df_flight_paths['start_lat'][i], df_flight_paths['end_lat'][i] ], + lon = [df_flight_paths['start_lon'][i], df_flight_paths['end_lon'][i]], + lat = [df_flight_paths['start_lat'][i], df_flight_paths['end_lat'][i]], mode = 'lines', line = dict( width = 1, color = 'red', ), - opacity = float(df_flight_paths['cnt'][i])/float(df_flight_paths['cnt'].max()), + opacity = float(df_flight_paths['cnt'][i]) / float(df_flight_paths['cnt'].max()), ) ) - -layout = dict( - title = 'Feb. 2011 American Airline flight paths<br>(Hover for airport names)', - showlegend = False, - geo = dict( - scope='north america', - projection=dict( type='azimuthal equal area' ), - showland = True, - landcolor = 'rgb(243, 243, 243)', - countrycolor = 'rgb(204, 204, 204)', - ), - ) - -fig = dict( data=flight_paths + airports, layout=layout ) -py.iplot( fig, filename='d3-flight-paths' ) + +layout = go.Layout( + title = dict( + text = 'Feb. 2011 American Airline flight paths<br>(Hover for airport names)' + ), + showlegend = False, + geo = dict( + scope = 'north america', + projection = dict(type = 'azimuthal equal area'), + showland = True, + landcolor = 'rgb(243, 243, 243)', + countrycolor = 'rgb(204, 204, 204)', + ), +) + +fig = go.Figure(data = flight_paths + airports, layout = layout) +py.iplot(fig, filename = 'd3-flight-paths')

-
+
@@ -108,12 +150,12 @@

US Flight Paths Map -
Out[1]:
+
Out[2]:
- +

@@ -123,63 +165,62 @@

US Flight Paths Map
-
-
+
-

London to NYC Great Circle¶

+

London to NYC Great Circle

-
In [2]:
+
In [3]:
-
import plotly.plotly as py
+
import plotly.plotly as py
+import plotly.graph_objs as go
 
-nyc_london = [ dict(
-    type = 'scattergeo',
-    lat = [ 40.7127, 51.5072 ],
-    lon = [ -74.0059, 0.1275 ],
+nyc_london = [go.Scattergeo(
+    lat = [40.7127, 51.5072],
+    lon = [-74.0059, 0.1275],
     mode = 'lines',
     line = dict(
         width = 2,
         color = 'blue',
     ),
-) ]
-    
-layout = dict(
-        title = 'London to NYC Great Circle',
-        showlegend = False,         
-        geo = dict(
-            resolution = 50,
-            showland = True,
-            showlakes = True,
-            landcolor = 'rgb(204, 204, 204)',
-            countrycolor = 'rgb(204, 204, 204)',
-            lakecolor = 'rgb(255, 255, 255)',
-            projection = dict( type="equirectangular" ),
-            coastlinewidth = 2,
-            lataxis = dict(
-                range = [ 20, 60 ],
-                showgrid = True,
-                tickmode = "linear",
-                dtick = 10
-            ),
-            lonaxis = dict(
-                range = [-100, 20],
-                showgrid = True,
-                tickmode = "linear",
-                dtick = 20
-            ),
-        )
+)]
+
+layout = go.Layout(
+    title = dict(
+        text = 'London to NYC Great Circle'
+    ),
+    showlegend = False,
+    geo = dict(
+        resolution = 50,
+        showland = True,
+        showlakes = True,
+        landcolor = 'rgb(204, 204, 204)',
+        countrycolor = 'rgb(204, 204, 204)',
+        lakecolor = 'rgb(255, 255, 255)',
+        projection = dict(type = "equirectangular"),
+        coastlinewidth = 2,
+        lataxis = dict(
+            range = [20, 60],
+            showgrid = True,
+            dtick = 10
+        ),
+        lonaxis = dict(
+            range = [-100, 20],
+            showgrid = True,
+            dtick = 20
+        ),
     )
-    
-fig = dict( data=nyc_london, layout=layout )
-py.iplot( fig, validate=False, filename='d3-great-circle' )
+)
+
+fig = go.Figure(data = nyc_london, layout = layout)
+py.iplot(fig, filename = 'd3-great-circle')
 
-
+
@@ -189,12 +230,12 @@

London to NYC Great Circle -
Out[2]:
+
Out[3]:
- +

@@ -204,93 +245,92 @@

London to NYC Great Circle
-
-
+
-

Contour lines on globe¶

+

Contour lines on globe

-
In [7]:
+
In [4]:
-
import plotly.plotly as py
-import pandas as pd
+
import plotly.plotly as py
+import plotly.graph_objs as go
 
+import pandas as pd
 try:
-    # Python 2
-    from itertools import izip
+    from itertools import izip# Python 2
 except ImportError:
-        # Python 3
-        izip = zip
+    izip = zip# Python 3
 
 df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/globe_contours.csv')
 df.head()
 
 contours = []
 
-scl = ['rgb(213,62,79)','rgb(244,109,67)','rgb(253,174,97)',\
-       'rgb(254,224,139)','rgb(255,255,191)','rgb(230,245,152)',\
-       'rgb(171,221,164)','rgb(102,194,165)','rgb(50,136,189)']
+scl = ['rgb(213,62,79)', 'rgb(244,109,67)', 'rgb(253,174,97)', \
+    'rgb(254,224,139)', 'rgb(255,255,191)', 'rgb(230,245,152)', \
+    'rgb(171,221,164)', 'rgb(102,194,165)', 'rgb(50,136,189)'
+]
 
 def pairwise(iterable):
     a = iter(iterable)
     return izip(a, a)
 
-i=0
+i = 0
 for lat, lon in pairwise(df.columns):
-    contours.append( dict(
-        type = 'scattergeo',
+    contours.append(go.Scattergeo(
         lon = df[lon],
         lat = df[lat],
         mode = 'lines',
         line = dict(
             width = 2,
             color = scl[i]
-        )
-    ) )
-    i = 0 if i+1 >= len(df.columns)/4 else i+1
-    
-layout = dict(
-        title = 'Contour lines over globe<br>(Click and drag to rotate)',
-        showlegend = False,         
-        geo = dict(
-            showland = True,
-            showlakes = True,
-            showcountries = True,
-            showocean = True,
-            countrywidth = 0.5,
-            landcolor = 'rgb(230, 145, 56)',
-            lakecolor = 'rgb(0, 255, 255)',
-            oceancolor = 'rgb(0, 255, 255)',
-            projection = dict( 
-                type = 'orthographic',
-                rotation = dict(
-                    lon = -100,
-                    lat = 40,
-                    roll = 0
-                )            
-            ),
-            lonaxis = dict( 
-                showgrid = True,
-                gridcolor = 'rgb(102, 102, 102)',
-                gridwidth = 0.5
-            ),
-            lataxis = dict( 
-                showgrid = True,
-                gridcolor = 'rgb(102, 102, 102)',
-                gridwidth = 0.5
+        )))
+    i = 0 if i + 1 >= len(df.columns) / 4 else i + 1
+
+layout = go.Layout(
+    title = dict(
+        text = 'Contour lines over globe<br>(Click and drag to rotate)'
+    ),
+    showlegend = False,
+    geo = dict(
+        showland = True,
+        showlakes = True,
+        showcountries = True,
+        showocean = True,
+        countrywidth = 0.5,
+        landcolor = 'rgb(230, 145, 56)',
+        lakecolor = 'rgb(0, 255, 255)',
+        oceancolor = 'rgb(0, 255, 255)',
+        projection = dict(
+            type = 'orthographic',
+            rotation = dict(
+                lon = -100,
+                lat = 40,
+                roll = 0
             )
+        ),
+        lonaxis = dict(
+            showgrid = True,
+            gridcolor = 'rgb(102, 102, 102)',
+            gridwidth = 0.5
+        ),
+        lataxis = dict(
+            showgrid = True,
+            gridcolor = 'rgb(102, 102, 102)',
+            gridwidth = 0.5
         )
     )
-    
-fig = dict( data=contours, layout=layout )
-py.iplot( fig, validate=False, filename='d3-globe' )
+)
+
+fig = go.Figure(data = contours, layout = layout)
+py.iplot(fig, filename = 'd3-globe')
 
-
+
@@ -300,12 +340,12 @@

Contour lines on globe -
Out[7]:
+
Out[4]:
- +

@@ -315,10 +355,9 @@

Contour lines on globe
-
-
+
-

Reference¶

See https://plot.ly/python/reference/#scattergeo for more information and chart attribute options!

+

Reference

See https://plot.ly/python/reference/#scattergeo for more information and chart attribute options!

diff --git a/_posts/python/maps/lines-on-maps/lines_on_maps.ipynb b/_posts/python/maps/lines-on-maps/lines_on_maps.ipynb index b9e915bfbebe..b3ae37adac72 100644 --- a/_posts/python/maps/lines-on-maps/lines_on_maps.ipynb +++ b/_posts/python/maps/lines-on-maps/lines_on_maps.ipynb @@ -14,30 +14,61 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### US Flight Paths Map" + "#### Version Check\n", + "Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'3.6.1'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly\n", + "plotly.__version__" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### US Flight Paths Map" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 1, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.plotly as py\n", + "import plotly.graph_objs as go\n", + "\n", "import pandas as pd\n", "\n", "df_airports = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_us_airport_traffic.csv')\n", @@ -46,54 +77,54 @@ "df_flight_paths = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv')\n", "df_flight_paths.head()\n", "\n", - "airports = [ dict(\n", - " type = 'scattergeo',\n", - " locationmode = 'USA-states',\n", - " lon = df_airports['long'],\n", - " lat = df_airports['lat'],\n", - " hoverinfo = 'text',\n", - " text = df_airports['airport'],\n", - " mode = 'markers',\n", - " marker = dict( \n", - " size=2, \n", - " color='rgb(255, 0, 0)',\n", - " line = dict(\n", - " width=3,\n", - " color='rgba(68, 68, 68, 0)'\n", - " )\n", - " ))]\n", - " \n", + "airports = [go.Scattergeo(\n", + " locationmode = 'USA-states',\n", + " lon = df_airports['long'],\n", + " lat = df_airports['lat'],\n", + " hoverinfo = 'text',\n", + " text = df_airports['airport'],\n", + " mode = 'markers',\n", + " marker = dict(\n", + " size = 2,\n", + " color = 'rgb(255, 0, 0)',\n", + " line = dict(\n", + " width = 3,\n", + " color = 'rgba(68, 68, 68, 0)'\n", + " )\n", + " ))]\n", + "\n", "flight_paths = []\n", - "for i in range( len( df_flight_paths ) ):\n", + "for i in range(len(df_flight_paths)):\n", " flight_paths.append(\n", - " dict(\n", - " type = 'scattergeo',\n", + " go.Scattergeo(\n", " locationmode = 'USA-states',\n", - " lon = [ df_flight_paths['start_lon'][i], df_flight_paths['end_lon'][i] ],\n", - " lat = [ df_flight_paths['start_lat'][i], df_flight_paths['end_lat'][i] ],\n", + " lon = [df_flight_paths['start_lon'][i], df_flight_paths['end_lon'][i]],\n", + " lat = [df_flight_paths['start_lat'][i], df_flight_paths['end_lat'][i]],\n", " mode = 'lines',\n", " line = dict(\n", " width = 1,\n", " color = 'red',\n", " ),\n", - " opacity = float(df_flight_paths['cnt'][i])/float(df_flight_paths['cnt'].max()),\n", + " opacity = float(df_flight_paths['cnt'][i]) / float(df_flight_paths['cnt'].max()),\n", " )\n", " )\n", - " \n", - "layout = dict(\n", - " title = 'Feb. 2011 American Airline flight paths
(Hover for airport names)',\n", - " showlegend = False, \n", - " geo = dict(\n", - " scope='north america',\n", - " projection=dict( type='azimuthal equal area' ),\n", - " showland = True,\n", - " landcolor = 'rgb(243, 243, 243)',\n", - " countrycolor = 'rgb(204, 204, 204)',\n", - " ),\n", - " )\n", - " \n", - "fig = dict( data=flight_paths + airports, layout=layout )\n", - "py.iplot( fig, filename='d3-flight-paths' )\n" + "\n", + "layout = go.Layout(\n", + " title = dict(\n", + " text = 'Feb. 2011 American Airline flight paths
(Hover for airport names)'\n", + " ),\n", + " showlegend = False,\n", + " geo = dict(\n", + " scope = 'north america',\n", + " projection = dict(type = 'azimuthal equal area'),\n", + " showland = True,\n", + " landcolor = 'rgb(243, 243, 243)',\n", + " countrycolor = 'rgb(204, 204, 204)',\n", + " ),\n", + ")\n", + "\n", + "fig = go.Figure(data = flight_paths + airports, layout = layout)\n", + "py.iplot(fig, filename = 'd3-flight-paths')" ] }, { @@ -105,66 +136,66 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.plotly as py\n", + "import plotly.graph_objs as go\n", "\n", - "nyc_london = [ dict(\n", - " type = 'scattergeo',\n", - " lat = [ 40.7127, 51.5072 ],\n", - " lon = [ -74.0059, 0.1275 ],\n", + "nyc_london = [go.Scattergeo(\n", + " lat = [40.7127, 51.5072],\n", + " lon = [-74.0059, 0.1275],\n", " mode = 'lines',\n", " line = dict(\n", " width = 2,\n", " color = 'blue',\n", " ),\n", - ") ]\n", - " \n", - "layout = dict(\n", - " title = 'London to NYC Great Circle',\n", - " showlegend = False, \n", - " geo = dict(\n", - " resolution = 50,\n", - " showland = True,\n", - " showlakes = True,\n", - " landcolor = 'rgb(204, 204, 204)',\n", - " countrycolor = 'rgb(204, 204, 204)',\n", - " lakecolor = 'rgb(255, 255, 255)',\n", - " projection = dict( type=\"equirectangular\" ),\n", - " coastlinewidth = 2,\n", - " lataxis = dict(\n", - " range = [ 20, 60 ],\n", - " showgrid = True,\n", - " tickmode = \"linear\",\n", - " dtick = 10\n", - " ),\n", - " lonaxis = dict(\n", - " range = [-100, 20],\n", - " showgrid = True,\n", - " tickmode = \"linear\",\n", - " dtick = 20\n", - " ),\n", - " )\n", + ")]\n", + "\n", + "layout = go.Layout(\n", + " title = dict(\n", + " text = 'London to NYC Great Circle'\n", + " ),\n", + " showlegend = False,\n", + " geo = dict(\n", + " resolution = 50,\n", + " showland = True,\n", + " showlakes = True,\n", + " landcolor = 'rgb(204, 204, 204)',\n", + " countrycolor = 'rgb(204, 204, 204)',\n", + " lakecolor = 'rgb(255, 255, 255)',\n", + " projection = dict(type = \"equirectangular\"),\n", + " coastlinewidth = 2,\n", + " lataxis = dict(\n", + " range = [20, 60],\n", + " showgrid = True,\n", + " dtick = 10\n", + " ),\n", + " lonaxis = dict(\n", + " range = [-100, 20],\n", + " showgrid = True,\n", + " dtick = 20\n", + " ),\n", " )\n", - " \n", - "fig = dict( data=nyc_london, layout=layout )\n", - "py.iplot( fig, validate=False, filename='d3-great-circle' )\n" + ")\n", + "\n", + "fig = go.Figure(data = nyc_london, layout = layout)\n", + "py.iplot(fig, filename = 'd3-great-circle')" ] }, { @@ -176,96 +207,96 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 7, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.plotly as py\n", - "import pandas as pd\n", + "import plotly.graph_objs as go\n", "\n", + "import pandas as pd\n", "try:\n", - " # Python 2\n", - " from itertools import izip\n", + " from itertools import izip# Python 2\n", "except ImportError:\n", - " # Python 3\n", - " izip = zip\n", + " izip = zip# Python 3\n", "\n", "df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/globe_contours.csv')\n", "df.head()\n", "\n", "contours = []\n", "\n", - "scl = ['rgb(213,62,79)','rgb(244,109,67)','rgb(253,174,97)',\\\n", - " 'rgb(254,224,139)','rgb(255,255,191)','rgb(230,245,152)',\\\n", - " 'rgb(171,221,164)','rgb(102,194,165)','rgb(50,136,189)']\n", + "scl = ['rgb(213,62,79)', 'rgb(244,109,67)', 'rgb(253,174,97)', \\\n", + " 'rgb(254,224,139)', 'rgb(255,255,191)', 'rgb(230,245,152)', \\\n", + " 'rgb(171,221,164)', 'rgb(102,194,165)', 'rgb(50,136,189)'\n", + "]\n", "\n", "def pairwise(iterable):\n", " a = iter(iterable)\n", " return izip(a, a)\n", "\n", - "i=0\n", + "i = 0\n", "for lat, lon in pairwise(df.columns):\n", - " contours.append( dict(\n", - " type = 'scattergeo',\n", + " contours.append(go.Scattergeo(\n", " lon = df[lon],\n", " lat = df[lat],\n", " mode = 'lines',\n", " line = dict(\n", " width = 2,\n", " color = scl[i]\n", - " )\n", - " ) )\n", - " i = 0 if i+1 >= len(df.columns)/4 else i+1\n", - " \n", - "layout = dict(\n", - " title = 'Contour lines over globe
(Click and drag to rotate)',\n", - " showlegend = False, \n", - " geo = dict(\n", - " showland = True,\n", - " showlakes = True,\n", - " showcountries = True,\n", - " showocean = True,\n", - " countrywidth = 0.5,\n", - " landcolor = 'rgb(230, 145, 56)',\n", - " lakecolor = 'rgb(0, 255, 255)',\n", - " oceancolor = 'rgb(0, 255, 255)',\n", - " projection = dict( \n", - " type = 'orthographic',\n", - " rotation = dict(\n", - " lon = -100,\n", - " lat = 40,\n", - " roll = 0\n", - " ) \n", - " ),\n", - " lonaxis = dict( \n", - " showgrid = True,\n", - " gridcolor = 'rgb(102, 102, 102)',\n", - " gridwidth = 0.5\n", - " ),\n", - " lataxis = dict( \n", - " showgrid = True,\n", - " gridcolor = 'rgb(102, 102, 102)',\n", - " gridwidth = 0.5\n", + " )))\n", + " i = 0 if i + 1 >= len(df.columns) / 4 else i + 1\n", + "\n", + "layout = go.Layout(\n", + " title = dict(\n", + " text = 'Contour lines over globe
(Click and drag to rotate)'\n", + " ),\n", + " showlegend = False,\n", + " geo = dict(\n", + " showland = True,\n", + " showlakes = True,\n", + " showcountries = True,\n", + " showocean = True,\n", + " countrywidth = 0.5,\n", + " landcolor = 'rgb(230, 145, 56)',\n", + " lakecolor = 'rgb(0, 255, 255)',\n", + " oceancolor = 'rgb(0, 255, 255)',\n", + " projection = dict(\n", + " type = 'orthographic',\n", + " rotation = dict(\n", + " lon = -100,\n", + " lat = 40,\n", + " roll = 0\n", " )\n", + " ),\n", + " lonaxis = dict(\n", + " showgrid = True,\n", + " gridcolor = 'rgb(102, 102, 102)',\n", + " gridwidth = 0.5\n", + " ),\n", + " lataxis = dict(\n", + " showgrid = True,\n", + " gridcolor = 'rgb(102, 102, 102)',\n", + " gridwidth = 0.5\n", " )\n", " )\n", - " \n", - "fig = dict( data=contours, layout=layout )\n", - "py.iplot( fig, validate=False, filename='d3-globe' )\n" + ")\n", + "\n", + "fig = go.Figure(data = contours, layout = layout)\n", + "py.iplot(fig, filename = 'd3-globe')" ] }, { @@ -280,7 +311,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 6, "metadata": { "scrolled": true }, @@ -314,23 +345,17 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-Quuo1K-build\n", + " Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-2_4qgef3\n", + "Building wheels for collected packages: publisher\n", + " Running setup.py bdist_wheel for publisher: started\n", + " Running setup.py bdist_wheel for publisher: finished with status 'done'\n", + " Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-4vhzj_jk\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + "Successfully built publisher\n", "Installing collected packages: publisher\n", - " Found existing installation: publisher 0.11\n", - " Uninstalling publisher-0.11:\n", - " Successfully uninstalled publisher-0.11\n", - " Running setup.py install for publisher ... \u001b[?25ldone\n", - "\u001b[?25hSuccessfully installed publisher-0.11\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning: The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n", - " \"You should import from nbconvert instead.\", ShimWarning)\n", - "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning: Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", - " warnings.warn('Did you \"Save\" this notebook before running this command? '\n" + " Found existing installation: publisher 0.13\n", + " Uninstalling publisher-0.13:\n", + " Successfully uninstalled publisher-0.13\n", + "Successfully installed publisher-0.13\n" ] } ], @@ -356,9 +381,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [] } @@ -366,21 +389,21 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.12" + "pygments_lexer": "ipython3", + "version": "3.7.1" } }, "nbformat": 4, From ecab1a7924bb528a540c4c1614d2637ac332892c Mon Sep 17 00:00:00 2001 From: Priyatharsan Rajasekar Date: Fri, 1 Mar 2019 12:41:42 -0500 Subject: [PATCH 3/6] title as text to tile - object utilization --- .../python/maps/bubble-maps/bubble-maps.ipynb | 24 +-- .../2015-06-30-Choropleth_maps.html | 163 +++++++++-------- .../choropleth-maps/Choropleth_maps.ipynb | 168 ++++++++++-------- .../county-choropleth/county_choropleth.ipynb | 54 ++---- 4 files changed, 210 insertions(+), 199 deletions(-) diff --git a/_posts/python/maps/bubble-maps/bubble-maps.ipynb b/_posts/python/maps/bubble-maps/bubble-maps.ipynb index e9abd3bef243..3372c625568b 100644 --- a/_posts/python/maps/bubble-maps/bubble-maps.ipynb +++ b/_posts/python/maps/bubble-maps/bubble-maps.ipynb @@ -26,7 +26,7 @@ { "data": { "text/plain": [ - "'3.6.0'" + "'3.6.1'" ] }, "execution_count": 1, @@ -260,7 +260,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -292,11 +292,11 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-7gmj7xbp\n", + " Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-8qikjqgp\n", "Building wheels for collected packages: publisher\n", " Running setup.py bdist_wheel for publisher: started\n", " Running setup.py bdist_wheel for publisher: finished with status 'done'\n", - " Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-a2n74gbm\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + " Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-uu9w7cmr\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", "Successfully built publisher\n", "Installing collected packages: publisher\n", " Found existing installation: publisher 0.13\n", @@ -304,20 +304,6 @@ " Successfully uninstalled publisher-0.13\n", "Successfully installed publisher-0.13\n" ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "C:\\Anaconda\\Anaconda3\\lib\\site-packages\\IPython\\nbconvert.py:13: ShimWarning:\n", - "\n", - "The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n", - "\n", - "C:\\Anaconda\\Anaconda3\\lib\\site-packages\\publisher\\publisher.py:53: UserWarning:\n", - "\n", - "Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", - "\n" - ] } ], "source": [ @@ -335,7 +321,7 @@ " has_thumbnail='true', thumbnail='thumbnail/bubble-map.jpg',\n", " language='python',\n", " page_type='example_index',\n", - " display_as='maps', order=3, # ipynb='~notebook_demo/1',\n", + " display_as='maps', order=3,\n", " uses_plotly_offline=False)" ] }, diff --git a/_posts/python/maps/choropleth-maps/2015-06-30-Choropleth_maps.html b/_posts/python/maps/choropleth-maps/2015-06-30-Choropleth_maps.html index 86f19be6b3a4..4d98859bab09 100644 --- a/_posts/python/maps/choropleth-maps/2015-06-30-Choropleth_maps.html +++ b/_posts/python/maps/choropleth-maps/2015-06-30-Choropleth_maps.html @@ -88,41 +88,49 @@

United States Choropleth Mapfor col in df.columns: df[col] = df[col].astype(str) -scl = [[0.0, 'rgb(242,240,247)'],[0.2, 'rgb(218,218,235)'],[0.4, 'rgb(188,189,220)'],\ - [0.6, 'rgb(158,154,200)'],[0.8, 'rgb(117,107,177)'],[1.0, 'rgb(84,39,143)']] - -df['text'] = df['state'] + '<br>' +\ - 'Beef '+df['beef']+' Dairy '+df['dairy']+'<br>'+\ - 'Fruits '+df['total fruits']+' Veggies ' + df['total veggies']+'<br>'+\ - 'Wheat '+df['wheat']+' Corn '+df['corn'] +scl = [ + [0.0, 'rgb(242,240,247)'], + [0.2, 'rgb(218,218,235)'], + [0.4, 'rgb(188,189,220)'], + [0.6, 'rgb(158,154,200)'], + [0.8, 'rgb(117,107,177)'], + [1.0, 'rgb(84,39,143)'] +] -data = [ go.Choropleth( - colorscale = scl, - autocolorscale = False, - locations = df['code'], - z = df['total exports'].astype(float), - locationmode = 'USA-states', - text = df['text'], - marker = dict( - line = dict ( - color = 'rgb(255,255,255)', - width = 2 - ) ), - colorbar = dict( - title = "Millions USD") - ) ] +df['text'] = df['state'] + '<br>' + \ + 'Beef ' + df['beef'] + ' Dairy ' + df['dairy'] + '<br>' + \ + 'Fruits ' + df['total fruits'] + ' Veggies ' + df['total veggies'] + '<br>' + \ + 'Wheat ' + df['wheat'] + ' Corn ' + df['corn'] + +data = [go.Choropleth( + colorscale = scl, + autocolorscale = False, + locations = df['code'], + z = df['total exports'].astype(float), + locationmode = 'USA-states', + text = df['text'], + marker = dict( + line = dict( + color = 'rgb(255,255,255)', + width = 2 + )), + colorbar = dict( + title = "Millions USD") +)] layout = go.Layout( - title = '2011 US Agriculture Exports by State<br>(Hover for breakdown)', - geo = dict( - scope='usa', - projection=dict( type='albers usa' ), - showlakes = True, - lakecolor = 'rgb(255, 255, 255)'), - ) - -fig = go.Figure( data=data, layout=layout ) -py.iplot(fig, filename='d3-cloropleth-map' ) + title = dict( + text = '2011 US Agriculture Exports by State<br>(Hover for breakdown)' + ), + geo = dict( + scope = 'usa', + projection = dict(type = 'albers usa'), + showlakes = True, + lakecolor = 'rgb(255, 255, 255)'), +) + +fig = go.Figure(data = data, layout = layout) +py.iplot(fig, filename = 'd3-cloropleth-map')

@@ -166,26 +174,34 @@

World Choropleth Mapdf = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_world_gdp_with_codes.csv') -data = [ go.Choropleth( - locations = df['CODE'], - z = df['GDP (BILLIONS)'], - text = df['COUNTRY'], - colorscale = [[0,"rgb(5, 10, 172)"],[0.35,"rgb(40, 60, 190)"],[0.5,"rgb(70, 100, 245)"],\ - [0.6,"rgb(90, 120, 245)"],[0.7,"rgb(106, 137, 247)"],[1,"rgb(220, 220, 220)"]], - autocolorscale = False, - reversescale = True, - marker = dict( - line = dict ( - color = 'rgb(180,180,180)', - width = 0.5 - ) ), - colorbar = dict( - tickprefix = '$', - title = 'GDP<br>Billions US$'), - ) ] +data = [go.Choropleth( + locations = df['CODE'], + z = df['GDP (BILLIONS)'], + text = df['COUNTRY'], + colorscale = [ + [0, "rgb(5, 10, 172)"], + [0.35, "rgb(40, 60, 190)"], + [0.5, "rgb(70, 100, 245)"], + [0.6, "rgb(90, 120, 245)"], + [0.7, "rgb(106, 137, 247)"], + [1, "rgb(220, 220, 220)"] + ], + autocolorscale = False, + reversescale = True, + marker = dict( + line = dict( + color = 'rgb(180,180,180)', + width = 0.5 + )), + colorbar = dict( + tickprefix = '$', + title = 'GDP<br>Billions US$'), +)] layout = go.Layout( - title = '2014 Global GDP', + title = dict( + text = '2014 Global GDP' + ), geo = dict( showframe = False, showcoastlines = False, @@ -193,19 +209,19 @@

World Choropleth Maptype = 'equirectangular' ) ), - annotations=[dict( - x=0.55, - y=0.1, - xref='paper', - yref='paper', - text='Source: <a href="https://www.cia.gov/library/publications/the-world-factbook/fields/2195.html">\ + annotations = [dict( + x = 0.55, + y = 0.1, + xref = 'paper', + yref = 'paper', + text = 'Source: <a href="https://www.cia.gov/library/publications/the-world-factbook/fields/2195.html">\ CIA World Factbook</a>', - showarrow=False + showarrow = False )] ) -fig = go.Figure( data=data, layout=layout ) -py.iplot(fig, filename='d3-world-map' ) +fig = go.Figure(data = data, layout = layout) +py.iplot(fig, filename = 'd3-world-map')

@@ -295,9 +311,10 @@

Choropleth Inset Map] layout = go.Layout( - title = 'Ebola cases reported by month in West Africa 2014<br> \ + title = dict( + text = 'Ebola cases reported by month in West Africa 2014<br> \ Source: <a href="https://data.hdx.rwlabs.org/dataset/rowca-ebola-cases">\ -HDX</a>', +HDX</a>'), geo = dict( resolution = 50, scope = 'africa', @@ -386,22 +403,26 @@

Full County Choroplethsdf_sample['County FIPS Code'] = df_sample['County FIPS Code'].apply(lambda x: str(x).zfill(3)) df_sample['FIPS'] = df_sample['State FIPS Code'] + df_sample['County FIPS Code'] -colorscale = ["#f7fbff","#ebf3fb","#deebf7","#d2e3f3","#c6dbef","#b3d2e9","#9ecae1", - "#85bcdb","#6baed6","#57a0ce","#4292c6","#3082be","#2171b5","#1361a9", - "#08519c","#0b4083","#08306b"] +colorscale = ["#f7fbff", "#ebf3fb", "#deebf7", "#d2e3f3", "#c6dbef", "#b3d2e9", "#9ecae1", + "#85bcdb", "#6baed6", "#57a0ce", "#4292c6", "#3082be", "#2171b5", "#1361a9", + "#08519c", "#0b4083", "#08306b" +] endpts = list(np.linspace(1, 12, len(colorscale) - 1)) fips = df_sample['FIPS'].tolist() values = df_sample['Unemployment Rate (%)'].tolist() fig = ff.create_choropleth( - fips=fips, values=values, scope=['usa'], - binning_endpoints=endpts, colorscale=colorscale, - show_state_data=False, - show_hover=True, centroid_marker={'opacity': 0}, - asp=2.9, title='USA by Unemployment %', - legend_title='% unemployed' + fips = fips, values = values, scope = ['usa'], + binning_endpoints = endpts, colorscale = colorscale, + show_state_data = False, + show_hover = True, centroid_marker = { + 'opacity': 0 + }, + asp = 2.9, + title = 'USA by Unemployment %', + legend_title = '% unemployed' ) -py.iplot(fig, filename='choropleth_full_usa') +py.iplot(fig, filename = 'choropleth_full_usa')

diff --git a/_posts/python/maps/choropleth-maps/Choropleth_maps.ipynb b/_posts/python/maps/choropleth-maps/Choropleth_maps.ipynb index 27eee6bac867..cd6dc4e2e2ee 100644 --- a/_posts/python/maps/choropleth-maps/Choropleth_maps.ipynb +++ b/_posts/python/maps/choropleth-maps/Choropleth_maps.ipynb @@ -76,41 +76,49 @@ "for col in df.columns:\n", " df[col] = df[col].astype(str)\n", "\n", - "scl = [[0.0, 'rgb(242,240,247)'],[0.2, 'rgb(218,218,235)'],[0.4, 'rgb(188,189,220)'],\\\n", - " [0.6, 'rgb(158,154,200)'],[0.8, 'rgb(117,107,177)'],[1.0, 'rgb(84,39,143)']]\n", + "scl = [\n", + " [0.0, 'rgb(242,240,247)'],\n", + " [0.2, 'rgb(218,218,235)'],\n", + " [0.4, 'rgb(188,189,220)'],\n", + " [0.6, 'rgb(158,154,200)'],\n", + " [0.8, 'rgb(117,107,177)'],\n", + " [1.0, 'rgb(84,39,143)']\n", + "]\n", "\n", - "df['text'] = df['state'] + '
' +\\\n", - " 'Beef '+df['beef']+' Dairy '+df['dairy']+'
'+\\\n", - " 'Fruits '+df['total fruits']+' Veggies ' + df['total veggies']+'
'+\\\n", - " 'Wheat '+df['wheat']+' Corn '+df['corn']\n", + "df['text'] = df['state'] + '
' + \\\n", + " 'Beef ' + df['beef'] + ' Dairy ' + df['dairy'] + '
' + \\\n", + " 'Fruits ' + df['total fruits'] + ' Veggies ' + df['total veggies'] + '
' + \\\n", + " 'Wheat ' + df['wheat'] + ' Corn ' + df['corn']\n", "\n", - "data = [ go.Choropleth(\n", - " colorscale = scl,\n", - " autocolorscale = False,\n", - " locations = df['code'],\n", - " z = df['total exports'].astype(float),\n", - " locationmode = 'USA-states',\n", - " text = df['text'],\n", - " marker = dict(\n", - " line = dict (\n", - " color = 'rgb(255,255,255)',\n", - " width = 2\n", - " ) ),\n", - " colorbar = dict(\n", - " title = \"Millions USD\")\n", - " ) ]\n", + "data = [go.Choropleth(\n", + " colorscale = scl,\n", + " autocolorscale = False,\n", + " locations = df['code'],\n", + " z = df['total exports'].astype(float),\n", + " locationmode = 'USA-states',\n", + " text = df['text'],\n", + " marker = dict(\n", + " line = dict(\n", + " color = 'rgb(255,255,255)',\n", + " width = 2\n", + " )),\n", + " colorbar = dict(\n", + " title = \"Millions USD\")\n", + ")]\n", "\n", "layout = go.Layout(\n", - " title = '2011 US Agriculture Exports by State
(Hover for breakdown)',\n", - " geo = dict(\n", - " scope='usa',\n", - " projection=dict( type='albers usa' ),\n", - " showlakes = True,\n", - " lakecolor = 'rgb(255, 255, 255)'),\n", - " )\n", - " \n", - "fig = go.Figure( data=data, layout=layout )\n", - "py.iplot(fig, filename='d3-cloropleth-map' )" + " title = dict(\n", + " text = '2011 US Agriculture Exports by State
(Hover for breakdown)'\n", + " ),\n", + " geo = dict(\n", + " scope = 'usa',\n", + " projection = dict(type = 'albers usa'),\n", + " showlakes = True,\n", + " lakecolor = 'rgb(255, 255, 255)'),\n", + ")\n", + "\n", + "fig = go.Figure(data = data, layout = layout)\n", + "py.iplot(fig, filename = 'd3-cloropleth-map')" ] }, { @@ -145,26 +153,34 @@ "\n", "df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_world_gdp_with_codes.csv')\n", "\n", - "data = [ go.Choropleth(\n", - " locations = df['CODE'],\n", - " z = df['GDP (BILLIONS)'],\n", - " text = df['COUNTRY'],\n", - " colorscale = [[0,\"rgb(5, 10, 172)\"],[0.35,\"rgb(40, 60, 190)\"],[0.5,\"rgb(70, 100, 245)\"],\\\n", - " [0.6,\"rgb(90, 120, 245)\"],[0.7,\"rgb(106, 137, 247)\"],[1,\"rgb(220, 220, 220)\"]],\n", - " autocolorscale = False,\n", - " reversescale = True,\n", - " marker = dict(\n", - " line = dict (\n", - " color = 'rgb(180,180,180)',\n", - " width = 0.5\n", - " ) ),\n", - " colorbar = dict(\n", - " tickprefix = '$',\n", - " title = 'GDP
Billions US$'),\n", - " ) ]\n", + "data = [go.Choropleth(\n", + " locations = df['CODE'],\n", + " z = df['GDP (BILLIONS)'],\n", + " text = df['COUNTRY'],\n", + " colorscale = [\n", + " [0, \"rgb(5, 10, 172)\"],\n", + " [0.35, \"rgb(40, 60, 190)\"],\n", + " [0.5, \"rgb(70, 100, 245)\"],\n", + " [0.6, \"rgb(90, 120, 245)\"],\n", + " [0.7, \"rgb(106, 137, 247)\"],\n", + " [1, \"rgb(220, 220, 220)\"]\n", + " ],\n", + " autocolorscale = False,\n", + " reversescale = True,\n", + " marker = dict(\n", + " line = dict(\n", + " color = 'rgb(180,180,180)',\n", + " width = 0.5\n", + " )),\n", + " colorbar = dict(\n", + " tickprefix = '$',\n", + " title = 'GDP
Billions US$'),\n", + ")]\n", "\n", "layout = go.Layout(\n", - " title = '2014 Global GDP',\n", + " title = dict(\n", + " text = '2014 Global GDP'\n", + " ),\n", " geo = dict(\n", " showframe = False,\n", " showcoastlines = False,\n", @@ -172,19 +188,19 @@ " type = 'equirectangular'\n", " )\n", " ),\n", - " annotations=[dict(\n", - " x=0.55,\n", - " y=0.1,\n", - " xref='paper',\n", - " yref='paper',\n", - " text='Source:
\\\n", + " annotations = [dict(\n", + " x = 0.55,\n", + " y = 0.1,\n", + " xref = 'paper',\n", + " yref = 'paper',\n", + " text = 'Source: \\\n", " CIA World Factbook',\n", - " showarrow=False\n", + " showarrow = False\n", " )]\n", ")\n", "\n", - "fig = go.Figure( data=data, layout=layout )\n", - "py.iplot(fig, filename='d3-world-map' )" + "fig = go.Figure(data = data, layout = layout)\n", + "py.iplot(fig, filename = 'd3-world-map')" ] }, { @@ -265,9 +281,10 @@ "]\n", "\n", "layout = go.Layout(\n", - " title = 'Ebola cases reported by month in West Africa 2014
\\\n", + " title = dict(\n", + " text = 'Ebola cases reported by month in West Africa 2014
\\\n", "Source: \\\n", - "HDX',\n", + "HDX'),\n", " geo = dict(\n", " resolution = 50,\n", " scope = 'africa',\n", @@ -354,22 +371,26 @@ "df_sample['County FIPS Code'] = df_sample['County FIPS Code'].apply(lambda x: str(x).zfill(3))\n", "df_sample['FIPS'] = df_sample['State FIPS Code'] + df_sample['County FIPS Code']\n", "\n", - "colorscale = [\"#f7fbff\",\"#ebf3fb\",\"#deebf7\",\"#d2e3f3\",\"#c6dbef\",\"#b3d2e9\",\"#9ecae1\",\n", - " \"#85bcdb\",\"#6baed6\",\"#57a0ce\",\"#4292c6\",\"#3082be\",\"#2171b5\",\"#1361a9\",\n", - " \"#08519c\",\"#0b4083\",\"#08306b\"]\n", + "colorscale = [\"#f7fbff\", \"#ebf3fb\", \"#deebf7\", \"#d2e3f3\", \"#c6dbef\", \"#b3d2e9\", \"#9ecae1\",\n", + " \"#85bcdb\", \"#6baed6\", \"#57a0ce\", \"#4292c6\", \"#3082be\", \"#2171b5\", \"#1361a9\",\n", + " \"#08519c\", \"#0b4083\", \"#08306b\"\n", + "]\n", "endpts = list(np.linspace(1, 12, len(colorscale) - 1))\n", "fips = df_sample['FIPS'].tolist()\n", "values = df_sample['Unemployment Rate (%)'].tolist()\n", "\n", "fig = ff.create_choropleth(\n", - " fips=fips, values=values, scope=['usa'],\n", - " binning_endpoints=endpts, colorscale=colorscale,\n", - " show_state_data=False,\n", - " show_hover=True, centroid_marker={'opacity': 0},\n", - " asp=2.9, title='USA by Unemployment %',\n", - " legend_title='% unemployed'\n", + " fips = fips, values = values, scope = ['usa'],\n", + " binning_endpoints = endpts, colorscale = colorscale,\n", + " show_state_data = False,\n", + " show_hover = True, centroid_marker = {\n", + " 'opacity': 0\n", + " },\n", + " asp = 2.9,\n", + " title = 'USA by Unemployment %',\n", + " legend_title = '% unemployed'\n", ")\n", - "py.iplot(fig, filename='choropleth_full_usa')" + "py.iplot(fig, filename = 'choropleth_full_usa')" ] }, { @@ -414,11 +435,11 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-c7dlx5_3\n", + " Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-uhi9ioyx\n", "Building wheels for collected packages: publisher\n", " Running setup.py bdist_wheel for publisher: started\n", " Running setup.py bdist_wheel for publisher: finished with status 'done'\n", - " Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-ng_5reyj\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + " Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-1qip_4zy\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", "Successfully built publisher\n", "Installing collected packages: publisher\n", " Found existing installation: publisher 0.13\n", @@ -442,8 +463,7 @@ " title = 'Python Choropleth Maps | Plotly',\n", " has_thumbnail='true', thumbnail='thumbnail/choropleth.jpg', \n", " language='python',\n", - " display_as='maps', order=1, ipynb='~notebook_demo/55',\n", - " uses_plotly_offline=False)" + " display_as='maps', order=1, ipynb='~notebook_demo/55')" ] }, { diff --git a/_posts/python/maps/county-choropleth/county_choropleth.ipynb b/_posts/python/maps/county-choropleth/county_choropleth.ipynb index 73c69c74872e..3a5f396b8ffc 100644 --- a/_posts/python/maps/county-choropleth/county_choropleth.ipynb +++ b/_posts/python/maps/county-choropleth/county_choropleth.ipynb @@ -27,7 +27,7 @@ { "data": { "text/plain": [ - "'2.7.0'" + "'3.6.1'" ] }, "execution_count": 1, @@ -85,37 +85,21 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": { - "scrolled": true + "scrolled": false }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/michael/.virtualenvs/plot2py2/local/lib/python2.7/site-packages/pandas/core/frame.py:6211: FutureWarning:\n", - "\n", - "Sorting because non-concatenation axis is not aligned. A future version\n", - "of pandas will change to not sort by default.\n", - "\n", - "To accept the future behavior, pass 'sort=False'.\n", - "\n", - "To retain the current behavior and silence the warning, pass 'sort=True'.\n", - "\n", - "\n" - ] - }, { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -152,19 +136,19 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 3, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -209,19 +193,19 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 4, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -263,19 +247,19 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 5, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -776,21 +760,21 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.15rc1" + "pygments_lexer": "ipython3", + "version": "3.7.1" } }, "nbformat": 4, From 51c57fe98db2ff2141cd60a9f12e20f04f1d94fa Mon Sep 17 00:00:00 2001 From: Priyatharsan Rajasekar Date: Fri, 1 Mar 2019 14:27:16 -0500 Subject: [PATCH 4/6] updated mapbox-dc --- .../python/maps/mapbox/2015-06-30-mapbox.html | 82 +++++++++---------- _posts/python/maps/mapbox/mapbox.ipynb | 35 +++++--- 2 files changed, 61 insertions(+), 56 deletions(-) diff --git a/_posts/python/maps/mapbox/2015-06-30-mapbox.html b/_posts/python/maps/mapbox/2015-06-30-mapbox.html index ff9afc1dcee1..45fe24160e44 100644 --- a/_posts/python/maps/mapbox/2015-06-30-mapbox.html +++ b/_posts/python/maps/mapbox/2015-06-30-mapbox.html @@ -4,21 +4,20 @@ name: Python Scatter Plots with Mapbox has_thumbnail: true thumbnail: thumbnail/scatter-mapbox.jpg -mapbox_access_token: pk.eyJ1IjoicHJpeWF0aGFyc2FuIiwiYSI6ImNqbGRyMGQ5YTBhcmkzcXF6YWZldnVvZXoifQ.sN7gyyHTIq1BSfHQRBZdHA -layout: user-guide -name: Scatter Plots on Mapbox -language: python title: Python Scatter Plots with Mapbox | Plotly -display_as: maps +name: Scatter Plots on Mapbox has_thumbnail: true +language: python page_type: example_index -order: 7 ipynb: ~notebook_demo/261 +display_as: maps +order: 7 +mapbox_access_token: pk.eyJ1IjoicHJpeWF0aGFyc2FuIiwiYSI6ImNqbGRyMGQ5YTBhcmkzcXF6YWZldnVvZXoifQ.sN7gyyHTIq1BSfHQRBZdHA +layout: user-guide --- {% raw %}
-
-
+

New to Plotly?

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks. @@ -28,8 +27,7 @@

New to Plotly?
-
-
+

Version Check

Plotly's Python package is updated frequently. Run pip install plotly --upgrade to make sure you're using the latest version.

@@ -41,11 +39,11 @@

Version CheckIn [1]:

-
import plotly
+
import plotly
 plotly.__version__
 
-
+
@@ -55,13 +53,13 @@

Version Check -
Out[1]:
+
Out[1]:
-
'3.4.2'
+
'3.6.1'

@@ -71,8 +69,7 @@

Version Check
-
-
+
@@ -139,7 +134,7 @@

Basic Example -
Out[2]:
+
Out[2]:
@@ -154,8 +149,7 @@

Basic Example @@ -224,7 +218,7 @@

Multiple Markers -
Out[3]:
+
Out[3]:
@@ -239,8 +233,7 @@

Multiple Markers
-
-
+
@@ -251,10 +244,10 @@

Nuclear Waste Sites on CampusesIn [4]:

@@ -320,7 +313,7 @@

Nuclear Waste Sites on Campuses -
Out[4]:
+
Out[4]:
@@ -335,8 +328,7 @@

Nuclear Waste Sites on Campuses
-
-
+

Reference

See https://plot.ly/python/reference/#scattermapbox for more information and options!

diff --git a/_posts/python/maps/mapbox/mapbox.ipynb b/_posts/python/maps/mapbox/mapbox.ipynb index 64993f989b87..57c0ce955707 100644 --- a/_posts/python/maps/mapbox/mapbox.ipynb +++ b/_posts/python/maps/mapbox/mapbox.ipynb @@ -26,7 +26,7 @@ { "data": { "text/plain": [ - "'3.4.2'" + "'3.6.1'" ] }, "execution_count": 1, @@ -107,8 +107,7 @@ " ),\n", ")\n", "\n", - "fig = dict(data=data, layout=layout)\n", - "\n", + "fig = go.Figure(data=data, layout=layout)\n", "py.iplot(fig, filename='Montreal Mapbox')" ] }, @@ -183,7 +182,7 @@ " ),\n", ")\n", "\n", - "fig = dict(data=data, layout=layout)\n", + "fig = go.Figure(data=data, layout=layout)\n", "py.iplot(fig, filename='Multiple Mapbox')" ] }, @@ -269,7 +268,7 @@ " ),\n", ")\n", "\n", - "fig = dict(data=data, layout=layout)\n", + "fig = go.Figure(data=data, layout=layout)\n", "py.iplot(fig, filename='Nuclear Waste Sites on American Campuses')" ] }, @@ -283,7 +282,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -309,6 +308,20 @@ }, "metadata": {}, "output_type": "display_data" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Anaconda\\Anaconda3\\lib\\site-packages\\IPython\\nbconvert.py:13: ShimWarning:\n", + "\n", + "The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n", + "\n", + "C:\\Anaconda\\Anaconda3\\lib\\site-packages\\publisher\\publisher.py:53: UserWarning:\n", + "\n", + "Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", + "\n" + ] } ], "source": [ @@ -341,21 +354,21 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.14" + "pygments_lexer": "ipython3", + "version": "3.7.1" } }, "nbformat": 4, From fc301070707b50d84a13f4c2a92b3da83af48ac4 Mon Sep 17 00:00:00 2001 From: Priyatharsan Rajasekar Date: Mon, 4 Mar 2019 17:03:50 -0500 Subject: [PATCH 5/6] all dicts to objects --- .../bubble-maps/2015-06-30-bubble-maps.html | 54 ++++++++------ .../python/maps/bubble-maps/bubble-maps.ipynb | 44 +++++++----- .../2015-06-30-Choropleth_maps.html | 52 +++++++------- .../choropleth-maps/Choropleth_maps.ipynb | 72 ++++++++++++------- .../2015-06-30-lines_on_maps.html | 40 ++++++----- .../maps/lines-on-maps/lines_on_maps.ipynb | 44 ++++++------ .../python/maps/mapbox/2015-06-30-mapbox.html | 20 +++--- _posts/python/maps/mapbox/mapbox.ipynb | 20 +++--- 8 files changed, 196 insertions(+), 150 deletions(-) diff --git a/_posts/python/maps/bubble-maps/2015-06-30-bubble-maps.html b/_posts/python/maps/bubble-maps/2015-06-30-bubble-maps.html index 18a912365058..6678389c231d 100644 --- a/_posts/python/maps/bubble-maps/2015-06-30-bubble-maps.html +++ b/_posts/python/maps/bubble-maps/2015-06-30-bubble-maps.html @@ -33,7 +33,7 @@

Version Check
-
In [2]:
+
In [1]:
@@ -79,7 +79,7 @@

United States Bubble Map
-
In [8]:
+
In [2]:
import plotly.plotly as py
@@ -106,20 +106,25 @@ 

United States Bubble Maptext = df_sub['text'], marker = dict( size = df_sub['pop']/scale, - # sizeref = 2. * max(df_sub['pop']/scale) / (25 ** 2), color = colors[i], - line = dict(width=0.5, color='rgb(40,40,40)'), + line = dict( + width=0.5, color='rgb(40,40,40)' + ), sizemode = 'area' ), name = '{0} - {1}'.format(lim[0],lim[1]) ) cities.append(city) layout = go.Layout( - title = '2014 US city populations<br>(Click legend to toggle traces)', + title = go.layout.Title( + text = '2014 US city populations<br>(Click legend to toggle traces)' + ), showlegend = True, - geo = dict( - scope='usa', - projection=dict( type='albers usa' ), + geo = go.layout.Geo( + scope = 'usa', + projection = go.layout.geo.Projection( + type='albers usa' + ), showland = True, landcolor = 'rgb(217, 217, 217)', subunitwidth=1, @@ -143,7 +148,7 @@

United States Bubble Map -
Out[8]:
+
Out[2]:
@@ -166,7 +171,7 @@

Ebola Cases in West Africa
-
In [9]:
+
In [3]:
import plotly.plotly as py
@@ -222,10 +227,11 @@ 

Ebola Cases in West Africa] layout = go.Layout( - title = 'Ebola cases reported by month in West Africa 2014<br> \ + title = go.layout.Title( + text = 'Ebola cases reported by month in West Africa 2014<br> \ Source: <a href="https://data.hdx.rwlabs.org/dataset/rowca-ebola-cases">\ -HDX</a>', - geo = dict( +HDX</a>'), + geo = go.layout.Geo( resolution = 50, scope = 'africa', showframe = False, @@ -234,17 +240,21 @@

Ebola Cases in West Africalandcolor = "rgb(229, 229, 229)", countrycolor = "rgb(255, 255, 255)" , coastlinecolor = "rgb(255, 255, 255)", - projection = dict( + projection = go.layout.geo.Projection( type = 'mercator' ), - lonaxis = dict( range= [ -15.0, -5.0 ] ), - lataxis = dict( range= [ 0.0, 12.0 ] ), - domain = dict( + lonaxis = go.layout.geo.Lonaxis( + range= [ -15.0, -5.0 ] + ), + lataxis = go.layout.geo.Lataxis( + range= [ 0.0, 12.0 ] + ), + domain = go.layout.geo.Domain( x = [ 0, 1 ], y = [ 0, 1 ] ) ), - geo2 = dict( + geo2 = go.layout.Geo( scope = 'africa', showframe = False, showland = True, @@ -256,7 +266,7 @@

Ebola Cases in West Africa), bgcolor = 'rgba(255, 255, 255, 0.0)', ), - legend = dict( + legend = go.layout.Legend( traceorder = 'reversed' ) ) @@ -275,7 +285,7 @@

Ebola Cases in West Africa -
Out[9]:
+
Out[3]:
diff --git a/_posts/python/maps/bubble-maps/bubble-maps.ipynb b/_posts/python/maps/bubble-maps/bubble-maps.ipynb index 3372c625568b..767f62fa09f5 100644 --- a/_posts/python/maps/bubble-maps/bubble-maps.ipynb +++ b/_posts/python/maps/bubble-maps/bubble-maps.ipynb @@ -100,20 +100,25 @@ " text = df_sub['text'],\n", " marker = dict(\n", " size = df_sub['pop']/scale,\n", - " # sizeref = 2. * max(df_sub['pop']/scale) / (25 ** 2),\n", " color = colors[i],\n", - " line = dict(width=0.5, color='rgb(40,40,40)'),\n", + " line = dict(\n", + " width=0.5, color='rgb(40,40,40)'\n", + " ),\n", " sizemode = 'area'\n", " ),\n", " name = '{0} - {1}'.format(lim[0],lim[1]) )\n", " cities.append(city)\n", "\n", "layout = go.Layout(\n", - " title = '2014 US city populations
(Click legend to toggle traces)',\n", + " title = go.layout.Title(\n", + " text = '2014 US city populations
(Click legend to toggle traces)'\n", + " ),\n", " showlegend = True,\n", - " geo = dict(\n", - " scope='usa',\n", - " projection=dict( type='albers usa' ),\n", + " geo = go.layout.Geo(\n", + " scope = 'usa',\n", + " projection = go.layout.geo.Projection(\n", + " type='albers usa'\n", + " ),\n", " showland = True,\n", " landcolor = 'rgb(217, 217, 217)',\n", " subunitwidth=1,\n", @@ -207,10 +212,11 @@ "]\n", "\n", "layout = go.Layout(\n", - " title = 'Ebola cases reported by month in West Africa 2014
\\\n", + " title = go.layout.Title(\n", + " text = 'Ebola cases reported by month in West Africa 2014
\\\n", "Source:
\\\n", - "HDX',\n", - " geo = dict(\n", + "HDX'),\n", + " geo = go.layout.Geo(\n", " resolution = 50,\n", " scope = 'africa',\n", " showframe = False,\n", @@ -219,17 +225,21 @@ " landcolor = \"rgb(229, 229, 229)\",\n", " countrycolor = \"rgb(255, 255, 255)\" ,\n", " coastlinecolor = \"rgb(255, 255, 255)\",\n", - " projection = dict(\n", + " projection = go.layout.geo.Projection(\n", " type = 'mercator'\n", " ),\n", - " lonaxis = dict( range= [ -15.0, -5.0 ] ),\n", - " lataxis = dict( range= [ 0.0, 12.0 ] ),\n", - " domain = dict(\n", + " lonaxis = go.layout.geo.Lonaxis(\n", + " range= [ -15.0, -5.0 ]\n", + " ),\n", + " lataxis = go.layout.geo.Lataxis(\n", + " range= [ 0.0, 12.0 ]\n", + " ),\n", + " domain = go.layout.geo.Domain(\n", " x = [ 0, 1 ],\n", " y = [ 0, 1 ]\n", " )\n", " ),\n", - " geo2 = dict(\n", + " geo2 = go.layout.Geo(\n", " scope = 'africa',\n", " showframe = False,\n", " showland = True,\n", @@ -241,7 +251,7 @@ " ),\n", " bgcolor = 'rgba(255, 255, 255, 0.0)',\n", " ),\n", - " legend = dict(\n", + " legend = go.layout.Legend(\n", " traceorder = 'reversed'\n", " )\n", ")\n", @@ -292,11 +302,11 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-8qikjqgp\n", + " Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-7diuf6ff\n", "Building wheels for collected packages: publisher\n", " Running setup.py bdist_wheel for publisher: started\n", " Running setup.py bdist_wheel for publisher: finished with status 'done'\n", - " Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-uu9w7cmr\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + " Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-mwz0xf63\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", "Successfully built publisher\n", "Installing collected packages: publisher\n", " Found existing installation: publisher 0.13\n", diff --git a/_posts/python/maps/choropleth-maps/2015-06-30-Choropleth_maps.html b/_posts/python/maps/choropleth-maps/2015-06-30-Choropleth_maps.html index 4d98859bab09..1adc6dc6fa7b 100644 --- a/_posts/python/maps/choropleth-maps/2015-06-30-Choropleth_maps.html +++ b/_posts/python/maps/choropleth-maps/2015-06-30-Choropleth_maps.html @@ -109,22 +109,22 @@

United States Choropleth Mapz = df['total exports'].astype(float), locationmode = 'USA-states', text = df['text'], - marker = dict( - line = dict( + marker = go.choropleth.Marker( + line = go.choropleth.marker.Line( color = 'rgb(255,255,255)', width = 2 )), - colorbar = dict( + colorbar = go.choropleth.ColorBar( title = "Millions USD") )] layout = go.Layout( - title = dict( + title = go.layout.Title( text = '2011 US Agriculture Exports by State<br>(Hover for breakdown)' ), - geo = dict( + geo = go.layout.Geo( scope = 'usa', - projection = dict(type = 'albers usa'), + projection = go.layout.geo.Projection(type = 'albers usa'), showlakes = True, lakecolor = 'rgb(255, 255, 255)'), ) @@ -188,28 +188,28 @@

World Choropleth Map], autocolorscale = False, reversescale = True, - marker = dict( - line = dict( + marker = go.choropleth.Marker( + line = go.choropleth.marker.Line( color = 'rgb(180,180,180)', width = 0.5 )), - colorbar = dict( + colorbar = go.choropleth.ColorBar( tickprefix = '$', title = 'GDP<br>Billions US$'), )] layout = go.Layout( - title = dict( + title = go.layout.Title( text = '2014 Global GDP' ), - geo = dict( + geo = go.layout.Geo( showframe = False, showcoastlines = False, - projection = dict( + projection = go.layout.geo.Projection( type = 'equirectangular' ) ), - annotations = [dict( + annotations = [go.layout.Annotation( x = 0.55, y = 0.1, xref = 'paper', @@ -277,10 +277,10 @@

Choropleth Inset Maplat = df[ df['Month'] == i ]['Lat'], text = df[ df['Month'] == i ]['Value'], name = months[i], - marker = dict( + marker = go.scattergeo.Marker( size = df[ df['Month'] == i ]['Value']/50, color = colors[i-6], - line = dict(width = 0) + line = go.scattergeo.marker.Line(width = 0) ), ) ) @@ -311,11 +311,11 @@

Choropleth Inset Map] layout = go.Layout( - title = dict( + title = go.layout.Title( text = 'Ebola cases reported by month in West Africa 2014<br> \ Source: <a href="https://data.hdx.rwlabs.org/dataset/rowca-ebola-cases">\ HDX</a>'), - geo = dict( + geo = go.layout.Geo( resolution = 50, scope = 'africa', showframe = False, @@ -324,29 +324,33 @@

Choropleth Inset Maplandcolor = "rgb(229, 229, 229)", countrycolor = "rgb(255, 255, 255)" , coastlinecolor = "rgb(255, 255, 255)", - projection = dict( + projection = go.layout.geo.Projection( type = 'equirectangular' ), - lonaxis = dict( range= [ -15.0, -5.0 ] ), - lataxis = dict( range= [ 0.0, 12.0 ] ), - domain = dict( + lonaxis = go.layout.geo.Lonaxis( + range= [ -15.0, -5.0 ] + ), + lataxis = go.layout.geo.Lataxis( + range= [ 0.0, 12.0 ] + ), + domain = go.layout.geo.Domain( x = [ 0, 1 ], y = [ 0, 1 ] ) ), - geo2 = dict( + geo2 = go.layout.Geo( scope = 'africa', showframe = False, showland = True, landcolor = "rgb(229, 229, 229)", showcountries = False, - domain = dict( + domain = go.layout.geo.Domain( x = [ 0, 0.6 ], y = [ 0, 0.6 ] ), bgcolor = 'rgba(255, 255, 255, 0.0)', ), - legend = dict( + legend = go.layout.Legend( traceorder = 'reversed' ) ) diff --git a/_posts/python/maps/choropleth-maps/Choropleth_maps.ipynb b/_posts/python/maps/choropleth-maps/Choropleth_maps.ipynb index cd6dc4e2e2ee..f584fba545cd 100644 --- a/_posts/python/maps/choropleth-maps/Choropleth_maps.ipynb +++ b/_posts/python/maps/choropleth-maps/Choropleth_maps.ipynb @@ -97,22 +97,22 @@ " z = df['total exports'].astype(float),\n", " locationmode = 'USA-states',\n", " text = df['text'],\n", - " marker = dict(\n", - " line = dict(\n", + " marker = go.choropleth.Marker(\n", + " line = go.choropleth.marker.Line(\n", " color = 'rgb(255,255,255)',\n", " width = 2\n", " )),\n", - " colorbar = dict(\n", + " colorbar = go.choropleth.ColorBar(\n", " title = \"Millions USD\")\n", ")]\n", "\n", "layout = go.Layout(\n", - " title = dict(\n", + " title = go.layout.Title(\n", " text = '2011 US Agriculture Exports by State
(Hover for breakdown)'\n", " ),\n", - " geo = dict(\n", + " geo = go.layout.Geo(\n", " scope = 'usa',\n", - " projection = dict(type = 'albers usa'),\n", + " projection = go.layout.geo.Projection(type = 'albers usa'),\n", " showlakes = True,\n", " lakecolor = 'rgb(255, 255, 255)'),\n", ")\n", @@ -167,28 +167,28 @@ " ],\n", " autocolorscale = False,\n", " reversescale = True,\n", - " marker = dict(\n", - " line = dict(\n", + " marker = go.choropleth.Marker(\n", + " line = go.choropleth.marker.Line(\n", " color = 'rgb(180,180,180)',\n", " width = 0.5\n", " )),\n", - " colorbar = dict(\n", + " colorbar = go.choropleth.ColorBar(\n", " tickprefix = '$',\n", " title = 'GDP
Billions US$'),\n", ")]\n", "\n", "layout = go.Layout(\n", - " title = dict(\n", + " title = go.layout.Title(\n", " text = '2014 Global GDP'\n", " ),\n", - " geo = dict(\n", + " geo = go.layout.Geo(\n", " showframe = False,\n", " showcoastlines = False,\n", - " projection = dict(\n", + " projection = go.layout.geo.Projection(\n", " type = 'equirectangular'\n", " )\n", " ),\n", - " annotations = [dict(\n", + " annotations = [go.layout.Annotation(\n", " x = 0.55,\n", " y = 0.1,\n", " xref = 'paper',\n", @@ -247,10 +247,10 @@ " lat = df[ df['Month'] == i ]['Lat'],\n", " text = df[ df['Month'] == i ]['Value'],\n", " name = months[i],\n", - " marker = dict(\n", + " marker = go.scattergeo.Marker(\n", " size = df[ df['Month'] == i ]['Value']/50,\n", " color = colors[i-6],\n", - " line = dict(width = 0)\n", + " line = go.scattergeo.marker.Line(width = 0)\n", " ),\n", " ) )\n", "\n", @@ -281,11 +281,11 @@ "]\n", "\n", "layout = go.Layout(\n", - " title = dict(\n", + " title = go.layout.Title(\n", " text = 'Ebola cases reported by month in West Africa 2014
\\\n", "Source:
\\\n", "HDX'),\n", - " geo = dict(\n", + " geo = go.layout.Geo(\n", " resolution = 50,\n", " scope = 'africa',\n", " showframe = False,\n", @@ -294,29 +294,33 @@ " landcolor = \"rgb(229, 229, 229)\",\n", " countrycolor = \"rgb(255, 255, 255)\" ,\n", " coastlinecolor = \"rgb(255, 255, 255)\",\n", - " projection = dict(\n", + " projection = go.layout.geo.Projection(\n", " type = 'equirectangular'\n", " ),\n", - " lonaxis = dict( range= [ -15.0, -5.0 ] ),\n", - " lataxis = dict( range= [ 0.0, 12.0 ] ),\n", - " domain = dict(\n", + " lonaxis = go.layout.geo.Lonaxis(\n", + " range= [ -15.0, -5.0 ]\n", + " ),\n", + " lataxis = go.layout.geo.Lataxis(\n", + " range= [ 0.0, 12.0 ]\n", + " ),\n", + " domain = go.layout.geo.Domain(\n", " x = [ 0, 1 ],\n", " y = [ 0, 1 ]\n", " )\n", " ),\n", - " geo2 = dict(\n", + " geo2 = go.layout.Geo(\n", " scope = 'africa',\n", " showframe = False,\n", " showland = True,\n", " landcolor = \"rgb(229, 229, 229)\",\n", " showcountries = False,\n", - " domain = dict(\n", + " domain = go.layout.geo.Domain(\n", " x = [ 0, 0.6 ],\n", " y = [ 0, 0.6 ]\n", " ),\n", " bgcolor = 'rgba(255, 255, 255, 0.0)',\n", " ),\n", - " legend = dict(\n", + " legend = go.layout.Legend(\n", " traceorder = 'reversed'\n", " )\n", ")\n", @@ -403,7 +407,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -435,11 +439,11 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-uhi9ioyx\n", + " Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-76l8i1ms\n", "Building wheels for collected packages: publisher\n", " Running setup.py bdist_wheel for publisher: started\n", " Running setup.py bdist_wheel for publisher: finished with status 'done'\n", - " Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-1qip_4zy\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + " Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-_3wa7m_l\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", "Successfully built publisher\n", "Installing collected packages: publisher\n", " Found existing installation: publisher 0.13\n", @@ -447,6 +451,20 @@ " Successfully uninstalled publisher-0.13\n", "Successfully installed publisher-0.13\n" ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Anaconda\\Anaconda3\\lib\\site-packages\\IPython\\nbconvert.py:13: ShimWarning:\n", + "\n", + "The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n", + "\n", + "C:\\Anaconda\\Anaconda3\\lib\\site-packages\\publisher\\publisher.py:53: UserWarning:\n", + "\n", + "Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", + "\n" + ] } ], "source": [ diff --git a/_posts/python/maps/lines-on-maps/2015-06-30-lines_on_maps.html b/_posts/python/maps/lines-on-maps/2015-06-30-lines_on_maps.html index e36836b97eda..58414ae13f71 100644 --- a/_posts/python/maps/lines-on-maps/2015-06-30-lines_on_maps.html +++ b/_posts/python/maps/lines-on-maps/2015-06-30-lines_on_maps.html @@ -97,10 +97,10 @@

US Flight Paths Maphoverinfo = 'text', text = df_airports['airport'], mode = 'markers', - marker = dict( + marker = go.scattergeo.Marker( size = 2, color = 'rgb(255, 0, 0)', - line = dict( + line = go.scattergeo.marker.Line( width = 3, color = 'rgba(68, 68, 68, 0)' ) @@ -114,7 +114,7 @@

US Flight Paths Maplon = [df_flight_paths['start_lon'][i], df_flight_paths['end_lon'][i]], lat = [df_flight_paths['start_lat'][i], df_flight_paths['end_lat'][i]], mode = 'lines', - line = dict( + line = go.scattergeo.Line( width = 1, color = 'red', ), @@ -123,13 +123,13 @@

US Flight Paths Map) layout = go.Layout( - title = dict( + title = go.layout.Title( text = 'Feb. 2011 American Airline flight paths<br>(Hover for airport names)' ), showlegend = False, - geo = dict( + geo = go.layout.Geo( scope = 'north america', - projection = dict(type = 'azimuthal equal area'), + projection = go.layout.geo.Projection(type = 'azimuthal equal area'), showland = True, landcolor = 'rgb(243, 243, 243)', countrycolor = 'rgb(204, 204, 204)', @@ -183,32 +183,34 @@

London to NYC Great Circlelat = [40.7127, 51.5072], lon = [-74.0059, 0.1275], mode = 'lines', - line = dict( + line = go.scattergeo.Line( width = 2, color = 'blue', ), )] layout = go.Layout( - title = dict( + title = go.layout.Title( text = 'London to NYC Great Circle' ), showlegend = False, - geo = dict( + geo = go.layout.Geo( resolution = 50, showland = True, showlakes = True, landcolor = 'rgb(204, 204, 204)', countrycolor = 'rgb(204, 204, 204)', lakecolor = 'rgb(255, 255, 255)', - projection = dict(type = "equirectangular"), + projection = go.layout.geo.Projection( + type = "equirectangular" + ), coastlinewidth = 2, - lataxis = dict( + lataxis = go.layout.geo.Lataxis( range = [20, 60], showgrid = True, dtick = 10 ), - lonaxis = dict( + lonaxis = go.layout.geo.Lonaxis( range = [-100, 20], showgrid = True, dtick = 20 @@ -285,18 +287,18 @@

Contour lines on globelon = df[lon], lat = df[lat], mode = 'lines', - line = dict( + line = go.scattergeo.Line( width = 2, color = scl[i] ))) i = 0 if i + 1 >= len(df.columns) / 4 else i + 1 layout = go.Layout( - title = dict( + title = go.layout.Title( text = 'Contour lines over globe<br>(Click and drag to rotate)' ), showlegend = False, - geo = dict( + geo = go.layout.Geo( showland = True, showlakes = True, showcountries = True, @@ -305,20 +307,20 @@

Contour lines on globelandcolor = 'rgb(230, 145, 56)', lakecolor = 'rgb(0, 255, 255)', oceancolor = 'rgb(0, 255, 255)', - projection = dict( + projection = go.layout.geo.Projection( type = 'orthographic', - rotation = dict( + rotation = go.layout.geo.projection.Rotation( lon = -100, lat = 40, roll = 0 ) ), - lonaxis = dict( + lonaxis = go.layout.geo.Lonaxis( showgrid = True, gridcolor = 'rgb(102, 102, 102)', gridwidth = 0.5 ), - lataxis = dict( + lataxis = go.layout.geo.Lataxis( showgrid = True, gridcolor = 'rgb(102, 102, 102)', gridwidth = 0.5 diff --git a/_posts/python/maps/lines-on-maps/lines_on_maps.ipynb b/_posts/python/maps/lines-on-maps/lines_on_maps.ipynb index b3ae37adac72..5ce015b04922 100644 --- a/_posts/python/maps/lines-on-maps/lines_on_maps.ipynb +++ b/_posts/python/maps/lines-on-maps/lines_on_maps.ipynb @@ -84,10 +84,10 @@ " hoverinfo = 'text',\n", " text = df_airports['airport'],\n", " mode = 'markers',\n", - " marker = dict(\n", + " marker = go.scattergeo.Marker(\n", " size = 2,\n", " color = 'rgb(255, 0, 0)',\n", - " line = dict(\n", + " line = go.scattergeo.marker.Line(\n", " width = 3,\n", " color = 'rgba(68, 68, 68, 0)'\n", " )\n", @@ -101,7 +101,7 @@ " lon = [df_flight_paths['start_lon'][i], df_flight_paths['end_lon'][i]],\n", " lat = [df_flight_paths['start_lat'][i], df_flight_paths['end_lat'][i]],\n", " mode = 'lines',\n", - " line = dict(\n", + " line = go.scattergeo.Line(\n", " width = 1,\n", " color = 'red',\n", " ),\n", @@ -110,13 +110,13 @@ " )\n", "\n", "layout = go.Layout(\n", - " title = dict(\n", + " title = go.layout.Title(\n", " text = 'Feb. 2011 American Airline flight paths
(Hover for airport names)'\n", " ),\n", " showlegend = False,\n", - " geo = dict(\n", + " geo = go.layout.Geo(\n", " scope = 'north america',\n", - " projection = dict(type = 'azimuthal equal area'),\n", + " projection = go.layout.geo.Projection(type = 'azimuthal equal area'),\n", " showland = True,\n", " landcolor = 'rgb(243, 243, 243)',\n", " countrycolor = 'rgb(204, 204, 204)',\n", @@ -161,32 +161,34 @@ " lat = [40.7127, 51.5072],\n", " lon = [-74.0059, 0.1275],\n", " mode = 'lines',\n", - " line = dict(\n", + " line = go.scattergeo.Line(\n", " width = 2,\n", " color = 'blue',\n", " ),\n", ")]\n", "\n", "layout = go.Layout(\n", - " title = dict(\n", + " title = go.layout.Title(\n", " text = 'London to NYC Great Circle'\n", " ),\n", " showlegend = False,\n", - " geo = dict(\n", + " geo = go.layout.Geo(\n", " resolution = 50,\n", " showland = True,\n", " showlakes = True,\n", " landcolor = 'rgb(204, 204, 204)',\n", " countrycolor = 'rgb(204, 204, 204)',\n", " lakecolor = 'rgb(255, 255, 255)',\n", - " projection = dict(type = \"equirectangular\"),\n", + " projection = go.layout.geo.Projection(\n", + " type = \"equirectangular\"\n", + " ),\n", " coastlinewidth = 2,\n", - " lataxis = dict(\n", + " lataxis = go.layout.geo.Lataxis(\n", " range = [20, 60],\n", " showgrid = True,\n", " dtick = 10\n", " ),\n", - " lonaxis = dict(\n", + " lonaxis = go.layout.geo.Lonaxis(\n", " range = [-100, 20],\n", " showgrid = True,\n", " dtick = 20\n", @@ -254,18 +256,18 @@ " lon = df[lon],\n", " lat = df[lat],\n", " mode = 'lines',\n", - " line = dict(\n", + " line = go.scattergeo.Line(\n", " width = 2,\n", " color = scl[i]\n", " )))\n", " i = 0 if i + 1 >= len(df.columns) / 4 else i + 1\n", "\n", "layout = go.Layout(\n", - " title = dict(\n", + " title = go.layout.Title(\n", " text = 'Contour lines over globe
(Click and drag to rotate)'\n", " ),\n", " showlegend = False,\n", - " geo = dict(\n", + " geo = go.layout.Geo(\n", " showland = True,\n", " showlakes = True,\n", " showcountries = True,\n", @@ -274,20 +276,20 @@ " landcolor = 'rgb(230, 145, 56)',\n", " lakecolor = 'rgb(0, 255, 255)',\n", " oceancolor = 'rgb(0, 255, 255)',\n", - " projection = dict(\n", + " projection = go.layout.geo.Projection(\n", " type = 'orthographic',\n", - " rotation = dict(\n", + " rotation = go.layout.geo.projection.Rotation(\n", " lon = -100,\n", " lat = 40,\n", " roll = 0\n", " )\n", " ),\n", - " lonaxis = dict(\n", + " lonaxis = go.layout.geo.Lonaxis(\n", " showgrid = True,\n", " gridcolor = 'rgb(102, 102, 102)',\n", " gridwidth = 0.5\n", " ),\n", - " lataxis = dict(\n", + " lataxis = go.layout.geo.Lataxis(\n", " showgrid = True,\n", " gridcolor = 'rgb(102, 102, 102)',\n", " gridwidth = 0.5\n", @@ -345,11 +347,11 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-2_4qgef3\n", + " Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-j78_c14c\n", "Building wheels for collected packages: publisher\n", " Running setup.py bdist_wheel for publisher: started\n", " Running setup.py bdist_wheel for publisher: finished with status 'done'\n", - " Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-4vhzj_jk\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + " Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-34r8gj90\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", "Successfully built publisher\n", "Installing collected packages: publisher\n", " Found existing installation: publisher 0.13\n", diff --git a/_posts/python/maps/mapbox/2015-06-30-mapbox.html b/_posts/python/maps/mapbox/2015-06-30-mapbox.html index 45fe24160e44..f753e5d4b5cc 100644 --- a/_posts/python/maps/mapbox/2015-06-30-mapbox.html +++ b/_posts/python/maps/mapbox/2015-06-30-mapbox.html @@ -98,7 +98,7 @@

Basic Examplelat=['45.5017'], lon=['-73.5673'], mode='markers', - marker=dict( + marker=go.scattermapbox.Marker( size=14 ), text=['Montreal'], @@ -108,10 +108,10 @@

Basic Examplelayout = go.Layout( autosize=True, hovermode='closest', - mapbox=dict( + mapbox=go.layout.Mapbox( accesstoken=mapbox_access_token, bearing=0, - center=dict( + center=go.layout.mapbox.Center( lat=45, lon=-73 ), @@ -178,7 +178,7 @@

Multiple Markers'-76.99656','-77.042438','-77.02821', '-77.01239'], mode='markers', - marker=dict( + marker=go.scattermapbox.Marker( size=9 ), text=["The coffee bar","Bistro Bohem","Black Cat", @@ -192,10 +192,10 @@

Multiple Markerslayout = go.Layout( autosize=True, hovermode='closest', - mapbox=dict( + mapbox=go.layout.Mapbox( accesstoken=mapbox_access_token, bearing=0, - center=dict( + center=go.layout.mapbox.Center( lat=38.92, lon=-77.07 ), @@ -261,7 +261,7 @@

Nuclear Waste Sites on Campuseslat=site_lat, lon=site_lon, mode='markers', - marker=dict( + marker=go.scattermapbox.Marker( size=17, color='rgb(255, 0, 0)', opacity=0.7 @@ -273,7 +273,7 @@

Nuclear Waste Sites on Campuseslat=site_lat, lon=site_lon, mode='markers', - marker=dict( + marker=go.scattermapbox.Marker( size=8, color='rgb(242, 177, 172)', opacity=0.7 @@ -286,10 +286,10 @@

Nuclear Waste Sites on Campusesautosize=True, hovermode='closest', showlegend=False, - mapbox=dict( + mapbox=go.layout.Mapbox( accesstoken=mapbox_access_token, bearing=0, - center=dict( + center=go.layout.mapbox.Center( lat=38, lon=-94 ), diff --git a/_posts/python/maps/mapbox/mapbox.ipynb b/_posts/python/maps/mapbox/mapbox.ipynb index 57c0ce955707..8ff2c9128c47 100644 --- a/_posts/python/maps/mapbox/mapbox.ipynb +++ b/_posts/python/maps/mapbox/mapbox.ipynb @@ -85,7 +85,7 @@ " lat=['45.5017'],\n", " lon=['-73.5673'],\n", " mode='markers',\n", - " marker=dict(\n", + " marker=go.scattermapbox.Marker(\n", " size=14\n", " ),\n", " text=['Montreal'],\n", @@ -95,10 +95,10 @@ "layout = go.Layout(\n", " autosize=True,\n", " hovermode='closest',\n", - " mapbox=dict(\n", + " mapbox=go.layout.Mapbox(\n", " accesstoken=mapbox_access_token,\n", " bearing=0,\n", - " center=dict(\n", + " center=go.layout.mapbox.Center(\n", " lat=45,\n", " lon=-73\n", " ),\n", @@ -156,7 +156,7 @@ " '-76.99656','-77.042438','-77.02821',\n", " '-77.01239'],\n", " mode='markers',\n", - " marker=dict(\n", + " marker=go.scattermapbox.Marker(\n", " size=9\n", " ),\n", " text=[\"The coffee bar\",\"Bistro Bohem\",\"Black Cat\",\n", @@ -170,10 +170,10 @@ "layout = go.Layout(\n", " autosize=True,\n", " hovermode='closest',\n", - " mapbox=dict(\n", + " mapbox=go.layout.Mapbox(\n", " accesstoken=mapbox_access_token,\n", " bearing=0,\n", - " center=dict(\n", + " center=go.layout.mapbox.Center(\n", " lat=38.92,\n", " lon=-77.07\n", " ),\n", @@ -230,7 +230,7 @@ " lat=site_lat,\n", " lon=site_lon,\n", " mode='markers',\n", - " marker=dict(\n", + " marker=go.scattermapbox.Marker(\n", " size=17,\n", " color='rgb(255, 0, 0)',\n", " opacity=0.7\n", @@ -242,7 +242,7 @@ " lat=site_lat,\n", " lon=site_lon,\n", " mode='markers',\n", - " marker=dict(\n", + " marker=go.scattermapbox.Marker(\n", " size=8,\n", " color='rgb(242, 177, 172)',\n", " opacity=0.7\n", @@ -255,10 +255,10 @@ " autosize=True,\n", " hovermode='closest',\n", " showlegend=False,\n", - " mapbox=dict(\n", + " mapbox=go.layout.Mapbox(\n", " accesstoken=mapbox_access_token,\n", " bearing=0,\n", - " center=dict(\n", + " center=go.layout.mapbox.Center(\n", " lat=38,\n", " lon=-94\n", " ),\n", From cafee2d7ca4af8838b7890794b7db8fb8d62f52d Mon Sep 17 00:00:00 2001 From: Priyatharsan Rajasekar Date: Mon, 4 Mar 2019 17:12:43 -0500 Subject: [PATCH 6/6] all dicts to objects2 --- .../maps/bubble-maps/2015-06-30-bubble-maps.html | 10 +++++----- _posts/python/maps/bubble-maps/bubble-maps.ipynb | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/_posts/python/maps/bubble-maps/2015-06-30-bubble-maps.html b/_posts/python/maps/bubble-maps/2015-06-30-bubble-maps.html index 6678389c231d..2a22423acbe7 100644 --- a/_posts/python/maps/bubble-maps/2015-06-30-bubble-maps.html +++ b/_posts/python/maps/bubble-maps/2015-06-30-bubble-maps.html @@ -104,10 +104,10 @@

United States Bubble Maplon = df_sub['lon'], lat = df_sub['lat'], text = df_sub['text'], - marker = dict( + marker = go.scattergeo.Marker( size = df_sub['pop']/scale, color = colors[i], - line = dict( + line = go.scattergeo.marker.Line( width=0.5, color='rgb(40,40,40)' ), sizemode = 'area' @@ -192,10 +192,10 @@

Ebola Cases in West Africalat = df[ df['Month'] == i ]['Lat'], text = df[ df['Month'] == i ]['Value'], name = months[i], - marker = dict( + marker = go.scattergeo.Marker( size = df[ df['Month'] == i ]['Value']/50, color = colors[i-6], - line = dict(width = 0) + line = go.scattergeo.marker.Line(width = 0) ) ) ) @@ -260,7 +260,7 @@

Ebola Cases in West Africashowland = True, landcolor = "rgb(229, 229, 229)", showcountries = False, - domain = dict( + domain = go.layout.geo.Domain( x = [ 0, 0.6 ], y = [ 0, 0.6 ] ), diff --git a/_posts/python/maps/bubble-maps/bubble-maps.ipynb b/_posts/python/maps/bubble-maps/bubble-maps.ipynb index 767f62fa09f5..81f90cd6ceab 100644 --- a/_posts/python/maps/bubble-maps/bubble-maps.ipynb +++ b/_posts/python/maps/bubble-maps/bubble-maps.ipynb @@ -98,10 +98,10 @@ " lon = df_sub['lon'],\n", " lat = df_sub['lat'],\n", " text = df_sub['text'],\n", - " marker = dict(\n", + " marker = go.scattergeo.Marker(\n", " size = df_sub['pop']/scale,\n", " color = colors[i],\n", - " line = dict(\n", + " line = go.scattergeo.marker.Line(\n", " width=0.5, color='rgb(40,40,40)'\n", " ),\n", " sizemode = 'area'\n", @@ -177,10 +177,10 @@ " lat = df[ df['Month'] == i ]['Lat'],\n", " text = df[ df['Month'] == i ]['Value'],\n", " name = months[i],\n", - " marker = dict(\n", + " marker = go.scattergeo.Marker(\n", " size = df[ df['Month'] == i ]['Value']/50,\n", " color = colors[i-6],\n", - " line = dict(width = 0)\n", + " line = go.scattergeo.marker.Line(width = 0)\n", " )\n", " )\n", " )\n", @@ -245,7 +245,7 @@ " showland = True,\n", " landcolor = \"rgb(229, 229, 229)\",\n", " showcountries = False,\n", - " domain = dict(\n", + " domain = go.layout.geo.Domain(\n", " x = [ 0, 0.6 ],\n", " y = [ 0, 0.6 ]\n", " ),\n", @@ -302,11 +302,11 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-7diuf6ff\n", + " Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-4lf8_u0r\n", "Building wheels for collected packages: publisher\n", " Running setup.py bdist_wheel for publisher: started\n", " Running setup.py bdist_wheel for publisher: finished with status 'done'\n", - " Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-mwz0xf63\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + " Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-rulskn3k\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", "Successfully built publisher\n", "Installing collected packages: publisher\n", " Found existing installation: publisher 0.13\n",