Skip to content

Commit

Permalink
Merge pull request plotly#1271 from plotly/convert-to-graphobjs
Browse files Browse the repository at this point in the history
update maps docs with dict -> graph_objs
  • Loading branch information
priyatharsan authored Mar 5, 2019
2 parents 367dce1 + cafee2d commit ecbe098
Show file tree
Hide file tree
Showing 9 changed files with 1,071 additions and 814 deletions.
178 changes: 113 additions & 65 deletions _posts/python/maps/bubble-maps/2015-06-30-bubble-maps.html

Large diffs are not rendered by default.

146 changes: 86 additions & 60 deletions _posts/python/maps/bubble-maps/bubble-maps.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,35 @@
"<br>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.1'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly\n",
"plotly.__version__"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -29,25 +58,26 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~jordanpeterson/1067.embed\" height=\"525px\" width=\"100%\"></iframe>"
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~PythonPlotBot/3195.embed\" height=\"525px\" width=\"100%\"></iframe>"
],
"text/plain": [
"<plotly.tools.PlotlyDisplay object>"
]
},
"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",
Expand All @@ -63,39 +93,43 @@
"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",
" text = df_sub['text'],\n",
" marker = dict(\n",
" marker = go.scattergeo.Marker(\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 = go.scattergeo.marker.Line(\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 = dict(\n",
" title = '2014 US city populations<br>(Click legend to toggle traces)',\n",
"layout = go.Layout(\n",
" title = go.layout.Title(\n",
" text = '2014 US city populations<br>(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",
" 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')"
]
},
{
Expand All @@ -107,19 +141,19 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~jordanpeterson/1144.embed\" height=\"525px\" width=\"100%\"></iframe>"
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~PythonPlotBot/2921.embed\" height=\"525px\" width=\"100%\"></iframe>"
],
"text/plain": [
"<plotly.tools.PlotlyDisplay object>"
]
},
"execution_count": 1,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -143,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",
Expand Down Expand Up @@ -178,10 +212,11 @@
"]\n",
"\n",
"layout = go.Layout(\n",
" title = 'Ebola cases reported by month in West Africa 2014<br> \\\n",
" title = go.layout.Title(\n",
" text = 'Ebola cases reported by month in West Africa 2014<br> \\\n",
"Source: <a href=\"https://data.hdx.rwlabs.org/dataset/rowca-ebola-cases\">\\\n",
"HDX</a>',\n",
" geo = dict(\n",
"HDX</a>'),\n",
" geo = go.layout.Geo(\n",
" resolution = 50,\n",
" scope = 'africa',\n",
" showframe = False,\n",
Expand All @@ -190,35 +225,39 @@
" 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",
" 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",
"\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')"
]
},
{
Expand All @@ -231,7 +270,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -263,30 +302,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-req-build-s5ETWe\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 ... \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-rulskn3k\\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"
]
},
{
"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"
]
}
],
Expand All @@ -305,7 +331,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)"
]
},
Expand All @@ -319,21 +345,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,
Expand Down
Loading

0 comments on commit ecbe098

Please sign in to comment.