Skip to content

Commit f959566

Browse files
committed
update plots in example-notebook.ipynb
1 parent 7fdf365 commit f959566

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

example-notebook.ipynb

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,6 @@
215215
"metadata": {},
216216
"outputs": [],
217217
"source": [
218-
"%%opts EdgePaths (color='w')\n",
219-
"\n",
220218
"import itertools\n",
221219
"\n",
222220
"# Create a learner and add data on homogeneous grid, so that we can plot it\n",
@@ -232,7 +230,7 @@
232230
" + learner.plot().relabel(\"With adaptive\")\n",
233231
" + learner2.plot(n, tri_alpha=0.4)\n",
234232
" + learner.plot(tri_alpha=0.4)\n",
235-
").cols(2)"
233+
").cols(2).opts({\"EdgePaths\": dict(color=\"w\")})"
236234
]
237235
},
238236
{
@@ -287,7 +285,7 @@
287285
"metadata": {},
288286
"outputs": [],
289287
"source": [
290-
"runner.live_plot(update_interval=0.1)"
288+
"runner.live_plot(update_interval=0.3)"
291289
]
292290
},
293291
{
@@ -392,7 +390,7 @@
392390
"metadata": {},
393391
"outputs": [],
394392
"source": [
395-
"runner.live_plot(update_interval=0.1)"
393+
"runner.live_plot(update_interval=1)"
396394
]
397395
},
398396
{
@@ -538,7 +536,7 @@
538536
"metadata": {},
539537
"outputs": [],
540538
"source": [
541-
"runner.live_plot(update_interval=0.1)"
539+
"runner.live_plot(update_interval=0.3)"
542540
]
543541
},
544542
{
@@ -602,15 +600,17 @@
602600
"metadata": {},
603601
"outputs": [],
604602
"source": [
605-
"%%opts Path {+framewise}\n",
606603
"def plot_cut(x1, x2, directions, learner=learner):\n",
607-
" cut_mapping = {'xyz'.index(d): x for d, x in zip(directions, [x1, x2])}\n",
608-
" return learner.plot_slice(cut_mapping)\n",
604+
" cut_mapping = {\"xyz\".index(d): x for d, x in zip(directions, [x1, x2])}\n",
605+
" return learner.plot_slice(cut_mapping).opts({\"Path\": dict(framewise=True)})\n",
609606
"\n",
610-
"dm = hv.DynamicMap(plot_cut, kdims=['v1', 'v2', 'directions'])\n",
611-
"dm.redim.values(v1=np.linspace(-1, 1),\n",
612-
" v2=np.linspace(-1, 1),\n",
613-
" directions=['xy', 'xz', 'yz'])"
607+
"\n",
608+
"dm = hv.DynamicMap(plot_cut, kdims=[\"v1\", \"v2\", \"directions\"])\n",
609+
"dm.redim.values(\n",
610+
" v1=np.linspace(-1, 1),\n",
611+
" v2=np.linspace(-1, 1),\n",
612+
" directions=[\"xy\", \"xz\", \"yz\"],\n",
613+
")"
614614
]
615615
},
616616
{
@@ -676,26 +676,36 @@
676676
"metadata": {},
677677
"outputs": [],
678678
"source": [
679-
"%%opts EdgePaths (color='w') Image [logz=True]\n",
680-
"\n",
681679
"from adaptive.runner import SequentialExecutor\n",
682680
"\n",
681+
"\n",
683682
"def uniform_sampling_2d(ip):\n",
684683
" from adaptive.learner.learner2D import areas\n",
684+
"\n",
685685
" A = areas(ip)\n",
686686
" return np.sqrt(A)\n",
687687
"\n",
688+
"\n",
688689
"def f_divergent_2d(xy):\n",
689690
" x, y = xy\n",
690-
" return 1 / (x**2 + y**2)\n",
691+
" return 1 / (x ** 2 + y ** 2)\n",
692+
"\n",
691693
"\n",
692-
"learner = adaptive.Learner2D(f_divergent_2d, [(-1, 1), (-1, 1)], loss_per_triangle=uniform_sampling_2d)\n",
694+
"def plot_logz(learner):\n",
695+
" p = learner.plot(tri_alpha=0.3).relabel(\"1 / (x^2 + y^2) in log scale\")\n",
696+
" return p.opts({\"Image\": dict(logz=True), \"EdgePaths\": dict(color=\"w\")})\n",
697+
"\n",
698+
"\n",
699+
"learner = adaptive.Learner2D(\n",
700+
" f_divergent_2d,\n",
701+
" bounds=[(-1, 1), (-1, 1)],\n",
702+
" loss_per_triangle=uniform_sampling_2d,\n",
703+
")\n",
693704
"\n",
694705
"# this takes a while, so use the async Runner so we know *something* is happening\n",
695706
"runner = adaptive.Runner(learner, goal=lambda l: l.loss() < 0.02)\n",
696707
"runner.live_info()\n",
697-
"runner.live_plot(update_interval=0.2,\n",
698-
" plotter=lambda l: l.plot(tri_alpha=0.3).relabel('1 / (x^2 + y^2) in log scale'))"
708+
"runner.live_plot(update_interval=0.2, plotter=plot_logz)"
699709
]
700710
},
701711
{
@@ -724,8 +734,6 @@
724734
"metadata": {},
725735
"outputs": [],
726736
"source": [
727-
"%%opts EdgePaths (color='w') Image [logz=True]\n",
728-
"\n",
729737
"def resolution_loss(ip, min_distance=0, max_distance=1):\n",
730738
" \"\"\"min_distance and max_distance should be in between 0 and 1\n",
731739
" because the total area is normalized to 1.\"\"\"\n",
@@ -757,7 +765,7 @@
757765
"\n",
758766
"learner = adaptive.Learner2D(f_divergent_2d, [(-1, 1), (-1, 1)], loss_per_triangle=loss)\n",
759767
"runner = adaptive.BlockingRunner(learner, goal=lambda l: l.loss() < 0.02)\n",
760-
"learner.plot(tri_alpha=0.3).relabel('1 / (x^2 + y^2) in log scale')"
768+
"plot_logz(learner)"
761769
]
762770
},
763771
{

0 commit comments

Comments
 (0)