Skip to content

Commit e2bb843

Browse files
give unique names (#6778)
1 parent e26616e commit e2bb843

File tree

1 file changed

+46
-50
lines changed

1 file changed

+46
-50
lines changed

examples/reference/panes/Plotly.ipynb

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -176,22 +176,18 @@
176176
"box_2 = go.Box(y=y1)\n",
177177
"data = [heatmap, box_1, box_2]\n",
178178
"\n",
179-
"fig = subplots.make_subplots(\n",
179+
"fig_layout = subplots.make_subplots(\n",
180180
" rows=2, cols=2, specs=[[{}, {}], [{'colspan': 2}, None]],\n",
181181
" subplot_titles=('First Subplot','Second Subplot', 'Third Subplot')\n",
182182
")\n",
183183
"\n",
184-
"fig.append_trace(box_1, 1, 1)\n",
185-
"fig.append_trace(box_2, 1, 2)\n",
186-
"fig.append_trace(heatmap, 2, 1)\n",
184+
"fig_layout.append_trace(box_1, 1, 1)\n",
185+
"fig_layout.append_trace(box_2, 1, 2)\n",
186+
"fig_layout.append_trace(heatmap, 2, 1)\n",
187187
"\n",
188-
"fig['layout'].update(height=600, width=600, title='i <3 subplots')\n",
188+
"fig_layout['layout'].update(height=600, width=600, title='i <3 subplots')\n",
189189
"\n",
190-
"# Conversion to dictionary only necessary if you want efficient updates\n",
191-
"fig = fig.to_dict()\n",
192-
"\n",
193-
"subplot_panel = pn.pane.Plotly(fig)\n",
194-
"subplot_panel"
190+
"pn.pane.Plotly(fig_layout)"
195191
]
196192
},
197193
{
@@ -220,11 +216,11 @@
220216
" ('Friday', 4), ('Saturday', 4), ('Sunday', 4)], columns=['Day', 'Orders']\n",
221217
")\n",
222218
"\n",
223-
"fig = px.line(data, x=\"Day\", y=\"Orders\")\n",
224-
"fig.update_traces(mode=\"lines+markers\", marker=dict(size=10), line=dict(width=4))\n",
225-
"fig.layout.autosize = True\n",
219+
"fig_responsive = px.line(data, x=\"Day\", y=\"Orders\")\n",
220+
"fig_responsive.update_traces(mode=\"lines+markers\", marker=dict(size=10), line=dict(width=4))\n",
221+
"fig_responsive.layout.autosize = True\n",
226222
"\n",
227-
"responsive = pn.pane.Plotly(fig, height=300)\n",
223+
"responsive = pn.pane.Plotly(fig_responsive, height=300)\n",
228224
"\n",
229225
"pn.Column('## A responsive plot', responsive, sizing_mode='stretch_width')"
230226
]
@@ -244,7 +240,7 @@
244240
"metadata": {},
245241
"outputs": [],
246242
"source": [
247-
"responsive_with_zoom = pn.pane.Plotly(fig, config={\"scrollZoom\": True}, height=300)\n",
243+
"responsive_with_zoom = pn.pane.Plotly(fig_responsive, config={\"scrollZoom\": True}, height=300)\n",
248244
"\n",
249245
"pn.Column('## A responsive and scroll zoomable plot', responsive_with_zoom, sizing_mode='stretch_width')"
250246
]
@@ -253,7 +249,7 @@
253249
"cell_type": "markdown",
254250
"metadata": {},
255251
"source": [
256-
"Try scrolling with the mouse!"
252+
"Try scrolling with the mouse over the plot!"
257253
]
258254
},
259255
{
@@ -294,10 +290,10 @@
294290
" margin=dict(t=50, b=50, r=50, l=50)\n",
295291
")\n",
296292
"\n",
297-
"fig = dict(data=[surface], layout=layout)\n",
293+
"fig_patch = dict(data=[surface], layout=layout)\n",
298294
"\n",
299-
"plotly_pane = pn.pane.Plotly(fig)\n",
300-
"plotly_pane"
295+
"plotly_pane_patch = pn.pane.Plotly(fig_patch)\n",
296+
"plotly_pane_patch"
301297
]
302298
},
303299
{
@@ -307,7 +303,7 @@
307303
"outputs": [],
308304
"source": [
309305
"surface.z = np.sin(z+1)\n",
310-
"plotly_pane.object = fig"
306+
"plotly_pane_patch.object = fig_patch"
311307
]
312308
},
313309
{
@@ -323,9 +319,9 @@
323319
"metadata": {},
324320
"outputs": [],
325321
"source": [
326-
"fig['layout']['width'] = 800\n",
322+
"fig_patch['layout']['width'] = 800\n",
327323
"\n",
328-
"plotly_pane.object = fig"
324+
"plotly_pane_patch.object = fig_patch"
329325
]
330326
},
331327
{
@@ -342,9 +338,9 @@
342338
"outputs": [],
343339
"source": [
344340
"surface.z = z\n",
345-
"fig['layout']['width'] = 500\n",
341+
"fig_patch['layout']['width'] = 500\n",
346342
"\n",
347-
"plotly_pane.object = fig"
343+
"plotly_pane_patch.object = fig_patch"
348344
]
349345
},
350346
{
@@ -386,9 +382,9 @@
386382
" close=df.loc[:start_index, \"AAPL.Close\"],\n",
387383
")\n",
388384
"\n",
389-
"fig = {\"data\": data, \"layout\": go.Layout(xaxis_rangeslider_visible=False)}\n",
385+
"fig_stream = {\"data\": data, \"layout\": go.Layout(xaxis_rangeslider_visible=False)}\n",
390386
"\n",
391-
"plotly_pane = pn.pane.Plotly(fig)\n",
387+
"plotly_pane_stream = pn.pane.Plotly(fig_stream)\n",
392388
"\n",
393389
"\n",
394390
"def stream():\n",
@@ -401,12 +397,12 @@
401397
" data[\"high\"] = df.loc[:index, \"AAPL.High\"]\n",
402398
" data[\"low\"] = df.loc[:index, \"AAPL.Low\"]\n",
403399
" data[\"close\"] = df.loc[:index, \"AAPL.Close\"]\n",
404-
" plotly_pane.object = fig\n",
400+
" plotly_pane_stream.object = fig_stream\n",
405401
"\n",
406402
"\n",
407403
"pn.state.add_periodic_callback(stream, period=100, count=50)\n",
408404
"\n",
409-
"plotly_pane"
405+
"plotly_pane_stream"
410406
]
411407
},
412408
{
@@ -448,8 +444,8 @@
448444
"layout = go.Layout(xaxis_rangeslider_visible=False)\n",
449445
"\n",
450446
"\n",
451-
"async def stream():\n",
452-
" for _ in range(0, 50):\n",
447+
"async def stream_generator():\n",
448+
" for _ in range(start_index, start_index+50):\n",
453449
" index = len(data.x)\n",
454450
" if index == len(df):\n",
455451
" index = 0\n",
@@ -464,7 +460,7 @@
464460
" await sleep(0.05)\n",
465461
"\n",
466462
"\n",
467-
"pn.pane.Plotly(stream)"
463+
"pn.pane.Plotly(stream_generator)"
468464
]
469465
},
470466
{
@@ -489,7 +485,7 @@
489485
"pn.extension(\"plotly\")\n",
490486
"\n",
491487
"\n",
492-
"fig = go.Figure()\n",
488+
"fig_in_place = go.Figure()\n",
493489
"\n",
494490
"button = pn.widgets.Button(name=\"Create\", button_type=\"primary\")\n",
495491
"\n",
@@ -498,34 +494,34 @@
498494
" mod = clicks % 3\n",
499495
" if mod == 1:\n",
500496
" button.name = \"Update\"\n",
501-
" fig.add_scatter(y=[2, 1, 4, 3])\n",
502-
" fig.add_bar(y=[2, 1, 4, 3])\n",
503-
" fig.layout.title = \"New Figure\"\n",
497+
" fig_in_place.add_scatter(y=[2, 1, 4, 3])\n",
498+
" fig_in_place.add_bar(y=[2, 1, 4, 3])\n",
499+
" fig_in_place.layout.title = \"New Figure\"\n",
504500
" elif mod == 2:\n",
505501
" button.name = \"Reset\"\n",
506-
" scatter = fig.data[0]\n",
502+
" scatter = fig_in_place.data[0]\n",
507503
" scatter.y = [3, 1, 4, 3]\n",
508-
" bar = fig.data[1]\n",
504+
" bar = fig_in_place.data[1]\n",
509505
" bar.y = [5, 3, 2, 8]\n",
510-
" fig.layout.title.text = \"Updated Figure\"\n",
506+
" fig_in_place.layout.title.text = \"Updated Figure\"\n",
511507
" else:\n",
512-
" fig.data = []\n",
513-
" fig.layout = {\"title\": \"\"}\n",
508+
" fig_in_place.data = []\n",
509+
" fig_in_place.layout = {\"title\": \"\"}\n",
514510
" button.name = \"Create\"\n",
515511
"\n",
516512
"pn.bind(handle_click, button.param.clicks, watch=True)\n",
517513
"button.clicks=1\n",
518514
"\n",
519-
"plotly_pane = pn.pane.Plotly(\n",
520-
" fig,\n",
515+
"plotly_pane_in_place = pn.pane.Plotly(\n",
516+
" fig_in_place,\n",
521517
" height=400,\n",
522518
" width=700,\n",
523519
" # link_figure=False\n",
524520
")\n",
525521
"\n",
526522
"pn.Column(\n",
527523
" button,\n",
528-
" plotly_pane,\n",
524+
" plotly_pane_in_place,\n",
529525
")"
530526
]
531527
},
@@ -567,11 +563,11 @@
567563
"df = pd.DataFrame({'x': x, 'y': y})\n",
568564
"\n",
569565
"# Create scatter plot\n",
570-
"fig = px.scatter(df, x='x', y='y', title='Click on a Point!', hover_name='x',)\n",
571-
"fig.update_traces(marker=dict(size=20))\n",
572-
"fig.update_layout(autosize=True, hovermode='closest')\n",
566+
"fig_events = px.scatter(df, x='x', y='y', title='Click on a Point!', hover_name='x',)\n",
567+
"fig_events.update_traces(marker=dict(size=20))\n",
568+
"fig_events.update_layout(autosize=True, hovermode='closest')\n",
573569
"\n",
574-
"plotly_pane=pn.pane.Plotly(fig, height=400, max_width=1200, sizing_mode=\"stretch_width\")\n",
570+
"plotly_pane_event=pn.pane.Plotly(fig_events, height=400, max_width=1200, sizing_mode=\"stretch_width\")\n",
575571
"\n",
576572
"# Define Child View\n",
577573
"def child_view(event):\n",
@@ -587,10 +583,10 @@
587583
" \n",
588584
" return f\"**You clicked point {index} at ({x}, {y}) on the Plotly Chart!**\"\n",
589585
"\n",
590-
"ichild_view = pn.bind(child_view, plotly_pane.param.click_data)\n",
586+
"ichild_view = pn.bind(child_view, plotly_pane_event.param.click_data)\n",
591587
"\n",
592588
"# Put things together\n",
593-
"pn.Column(plotly_pane, ichild_view)"
589+
"pn.Column(plotly_pane_event, ichild_view)"
594590
]
595591
},
596592
{
@@ -612,7 +608,7 @@
612608
"source": [
613609
"event_parameters = [\"click_data\", \"click_annotation_data\", \"hover_data\", \"relayout_data\", \"restyle_data\", \"selected_data\", \"viewport\"]\n",
614610
"\n",
615-
"pn.Param(plotly_pane, parameters=event_parameters, max_width=1100, name=\"Plotly Event Parameters\")"
611+
"pn.Param(plotly_pane_event, parameters=event_parameters, max_width=1100, name=\"Plotly Event Parameters\")"
616612
]
617613
},
618614
{

0 commit comments

Comments
 (0)