Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ecbe098

Browse files
authored
Merge pull request plotly#1271 from plotly/convert-to-graphobjs
update maps docs with dict -> graph_objs
2 parents 367dce1 + cafee2d commit ecbe098

File tree

9 files changed

+1071
-814
lines changed

9 files changed

+1071
-814
lines changed

_posts/python/maps/bubble-maps/2015-06-30-bubble-maps.html

Lines changed: 113 additions & 65 deletions
Large diffs are not rendered by default.

_posts/python/maps/bubble-maps/bubble-maps.ipynb

Lines changed: 86 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,35 @@
1010
"<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!"
1111
]
1212
},
13+
{
14+
"cell_type": "markdown",
15+
"metadata": {},
16+
"source": [
17+
"#### Version Check\n",
18+
"Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version."
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 1,
24+
"metadata": {},
25+
"outputs": [
26+
{
27+
"data": {
28+
"text/plain": [
29+
"'3.6.1'"
30+
]
31+
},
32+
"execution_count": 1,
33+
"metadata": {},
34+
"output_type": "execute_result"
35+
}
36+
],
37+
"source": [
38+
"import plotly\n",
39+
"plotly.__version__"
40+
]
41+
},
1342
{
1443
"cell_type": "markdown",
1544
"metadata": {},
@@ -29,25 +58,26 @@
2958
},
3059
{
3160
"cell_type": "code",
32-
"execution_count": 1,
61+
"execution_count": 2,
3362
"metadata": {},
3463
"outputs": [
3564
{
3665
"data": {
3766
"text/html": [
38-
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~jordanpeterson/1067.embed\" height=\"525px\" width=\"100%\"></iframe>"
67+
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~PythonPlotBot/3195.embed\" height=\"525px\" width=\"100%\"></iframe>"
3968
],
4069
"text/plain": [
4170
"<plotly.tools.PlotlyDisplay object>"
4271
]
4372
},
44-
"execution_count": 1,
73+
"execution_count": 2,
4574
"metadata": {},
4675
"output_type": "execute_result"
4776
}
4877
],
4978
"source": [
5079
"import plotly.plotly as py\n",
80+
"import plotly.graph_objs as go\n",
5181
"\n",
5282
"import pandas as pd\n",
5383
"\n",
@@ -63,39 +93,43 @@
6393
"for i in range(len(limits)):\n",
6494
" lim = limits[i]\n",
6595
" df_sub = df[lim[0]:lim[1]]\n",
66-
" city = dict(\n",
67-
" type = 'scattergeo',\n",
96+
" city = go.Scattergeo(\n",
6897
" locationmode = 'USA-states',\n",
6998
" lon = df_sub['lon'],\n",
7099
" lat = df_sub['lat'],\n",
71100
" text = df_sub['text'],\n",
72-
" marker = dict(\n",
101+
" marker = go.scattergeo.Marker(\n",
73102
" size = df_sub['pop']/scale,\n",
74-
" # sizeref = 2. * max(df_sub['pop']/scale) / (25 ** 2),\n",
75103
" color = colors[i],\n",
76-
" line = dict(width=0.5, color='rgb(40,40,40)'),\n",
104+
" line = go.scattergeo.marker.Line(\n",
105+
" width=0.5, color='rgb(40,40,40)'\n",
106+
" ),\n",
77107
" sizemode = 'area'\n",
78108
" ),\n",
79109
" name = '{0} - {1}'.format(lim[0],lim[1]) )\n",
80110
" cities.append(city)\n",
81111
"\n",
82-
"layout = dict(\n",
83-
" title = '2014 US city populations<br>(Click legend to toggle traces)',\n",
112+
"layout = go.Layout(\n",
113+
" title = go.layout.Title(\n",
114+
" text = '2014 US city populations<br>(Click legend to toggle traces)'\n",
115+
" ),\n",
84116
" showlegend = True,\n",
85-
" geo = dict(\n",
86-
" scope='usa',\n",
87-
" projection=dict( type='albers usa' ),\n",
117+
" geo = go.layout.Geo(\n",
118+
" scope = 'usa',\n",
119+
" projection = go.layout.geo.Projection(\n",
120+
" type='albers usa'\n",
121+
" ),\n",
88122
" showland = True,\n",
89123
" landcolor = 'rgb(217, 217, 217)',\n",
90124
" subunitwidth=1,\n",
91125
" countrywidth=1,\n",
92126
" subunitcolor=\"rgb(255, 255, 255)\",\n",
93127
" countrycolor=\"rgb(255, 255, 255)\"\n",
94-
" ),\n",
128+
" )\n",
95129
" )\n",
96130
"\n",
97-
"fig = dict(data=cities, layout=layout)\n",
98-
"py.iplot(fig, validate=False, filename='d3-bubble-map-populations')"
131+
"fig = go.Figure(data=cities, layout=layout)\n",
132+
"py.iplot(fig, filename='d3-bubble-map-populations')"
99133
]
100134
},
101135
{
@@ -107,19 +141,19 @@
107141
},
108142
{
109143
"cell_type": "code",
110-
"execution_count": 1,
144+
"execution_count": 3,
111145
"metadata": {},
112146
"outputs": [
113147
{
114148
"data": {
115149
"text/html": [
116-
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~jordanpeterson/1144.embed\" height=\"525px\" width=\"100%\"></iframe>"
150+
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~PythonPlotBot/2921.embed\" height=\"525px\" width=\"100%\"></iframe>"
117151
],
118152
"text/plain": [
119153
"<plotly.tools.PlotlyDisplay object>"
120154
]
121155
},
122-
"execution_count": 1,
156+
"execution_count": 3,
123157
"metadata": {},
124158
"output_type": "execute_result"
125159
}
@@ -143,10 +177,10 @@
143177
" lat = df[ df['Month'] == i ]['Lat'],\n",
144178
" text = df[ df['Month'] == i ]['Value'],\n",
145179
" name = months[i],\n",
146-
" marker = dict(\n",
180+
" marker = go.scattergeo.Marker(\n",
147181
" size = df[ df['Month'] == i ]['Value']/50,\n",
148182
" color = colors[i-6],\n",
149-
" line = dict(width = 0)\n",
183+
" line = go.scattergeo.marker.Line(width = 0)\n",
150184
" )\n",
151185
" )\n",
152186
" )\n",
@@ -178,10 +212,11 @@
178212
"]\n",
179213
"\n",
180214
"layout = go.Layout(\n",
181-
" title = 'Ebola cases reported by month in West Africa 2014<br> \\\n",
215+
" title = go.layout.Title(\n",
216+
" text = 'Ebola cases reported by month in West Africa 2014<br> \\\n",
182217
"Source: <a href=\"https://data.hdx.rwlabs.org/dataset/rowca-ebola-cases\">\\\n",
183-
"HDX</a>',\n",
184-
" geo = dict(\n",
218+
"HDX</a>'),\n",
219+
" geo = go.layout.Geo(\n",
185220
" resolution = 50,\n",
186221
" scope = 'africa',\n",
187222
" showframe = False,\n",
@@ -190,35 +225,39 @@
190225
" landcolor = \"rgb(229, 229, 229)\",\n",
191226
" countrycolor = \"rgb(255, 255, 255)\" ,\n",
192227
" coastlinecolor = \"rgb(255, 255, 255)\",\n",
193-
" projection = dict(\n",
228+
" projection = go.layout.geo.Projection(\n",
194229
" type = 'mercator'\n",
195230
" ),\n",
196-
" lonaxis = dict( range= [ -15.0, -5.0 ] ),\n",
197-
" lataxis = dict( range= [ 0.0, 12.0 ] ),\n",
198-
" domain = dict(\n",
231+
" lonaxis = go.layout.geo.Lonaxis(\n",
232+
" range= [ -15.0, -5.0 ]\n",
233+
" ),\n",
234+
" lataxis = go.layout.geo.Lataxis(\n",
235+
" range= [ 0.0, 12.0 ]\n",
236+
" ),\n",
237+
" domain = go.layout.geo.Domain(\n",
199238
" x = [ 0, 1 ],\n",
200239
" y = [ 0, 1 ]\n",
201240
" )\n",
202241
" ),\n",
203-
" geo2 = dict(\n",
242+
" geo2 = go.layout.Geo(\n",
204243
" scope = 'africa',\n",
205244
" showframe = False,\n",
206245
" showland = True,\n",
207246
" landcolor = \"rgb(229, 229, 229)\",\n",
208247
" showcountries = False,\n",
209-
" domain = dict(\n",
248+
" domain = go.layout.geo.Domain(\n",
210249
" x = [ 0, 0.6 ],\n",
211250
" y = [ 0, 0.6 ]\n",
212251
" ),\n",
213252
" bgcolor = 'rgba(255, 255, 255, 0.0)',\n",
214253
" ),\n",
215-
" legend = dict(\n",
254+
" legend = go.layout.Legend(\n",
216255
" traceorder = 'reversed'\n",
217256
" )\n",
218257
")\n",
219258
"\n",
220259
"fig = go.Figure(layout=layout, data=cases+inset)\n",
221-
"py.iplot(fig, validate=False, filename='West Africa Ebola cases 2014')"
260+
"py.iplot(fig, filename='West Africa Ebola cases 2014')"
222261
]
223262
},
224263
{
@@ -231,7 +270,7 @@
231270
},
232271
{
233272
"cell_type": "code",
234-
"execution_count": 2,
273+
"execution_count": 5,
235274
"metadata": {},
236275
"outputs": [
237276
{
@@ -263,30 +302,17 @@
263302
"output_type": "stream",
264303
"text": [
265304
"Collecting git+https://github.com/plotly/publisher.git\n",
266-
" Cloning https://github.com/plotly/publisher.git to /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-req-build-s5ETWe\n",
305+
" Cloning https://github.com/plotly/publisher.git to c:\\users\\priyat~1\\appdata\\local\\temp\\pip-req-build-4lf8_u0r\n",
267306
"Building wheels for collected packages: publisher\n",
268-
" Running setup.py bdist_wheel for publisher ... \u001b[?25ldone\n",
269-
"\u001b[?25h Stored in directory: /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-ephem-wheel-cache-muSfgQ/wheels/99/3e/a0/fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n",
307+
" Running setup.py bdist_wheel for publisher: started\n",
308+
" Running setup.py bdist_wheel for publisher: finished with status 'done'\n",
309+
" Stored in directory: C:\\Users\\PRIYAT~1\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-rulskn3k\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n",
270310
"Successfully built publisher\n",
271311
"Installing collected packages: publisher\n",
272-
" Found existing installation: publisher 0.11\n",
273-
" Uninstalling publisher-0.11:\n",
274-
" Successfully uninstalled publisher-0.11\n",
275-
"Successfully installed publisher-0.11\n"
276-
]
277-
},
278-
{
279-
"name": "stderr",
280-
"output_type": "stream",
281-
"text": [
282-
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning:\n",
283-
"\n",
284-
"The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n",
285-
"\n",
286-
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning:\n",
287-
"\n",
288-
"Did you \"Save\" this notebook before running this command? Remember to save, always save.\n",
289-
"\n"
312+
" Found existing installation: publisher 0.13\n",
313+
" Uninstalling publisher-0.13:\n",
314+
" Successfully uninstalled publisher-0.13\n",
315+
"Successfully installed publisher-0.13\n"
290316
]
291317
}
292318
],
@@ -305,7 +331,7 @@
305331
" has_thumbnail='true', thumbnail='thumbnail/bubble-map.jpg',\n",
306332
" language='python',\n",
307333
" page_type='example_index',\n",
308-
" display_as='maps', order=3, # ipynb='~notebook_demo/1',\n",
334+
" display_as='maps', order=3,\n",
309335
" uses_plotly_offline=False)"
310336
]
311337
},
@@ -319,21 +345,21 @@
319345
],
320346
"metadata": {
321347
"kernelspec": {
322-
"display_name": "Python 2",
348+
"display_name": "Python 3",
323349
"language": "python",
324-
"name": "python2"
350+
"name": "python3"
325351
},
326352
"language_info": {
327353
"codemirror_mode": {
328354
"name": "ipython",
329-
"version": 2
355+
"version": 3
330356
},
331357
"file_extension": ".py",
332358
"mimetype": "text/x-python",
333359
"name": "python",
334360
"nbconvert_exporter": "python",
335-
"pygments_lexer": "ipython2",
336-
"version": "2.7.12"
361+
"pygments_lexer": "ipython3",
362+
"version": "3.7.1"
337363
}
338364
},
339365
"nbformat": 4,

0 commit comments

Comments
 (0)