Skip to content

Commit 5b8024e

Browse files
committedMay 25, 2022
making it work on mybinder
1 parent 96db7dd commit 5b8024e

File tree

1 file changed

+20
-32
lines changed

1 file changed

+20
-32
lines changed
 

‎examples/widgets_playground.ipynb

+20-32
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"outputs": [],
1919
"source": [
2020
"import subprocess\n",
21-
"for package in ('ipywidgets', 'matplotlib', 'ipympl'):\n",
21+
"for package in ('ipywidgets', 'matplotlib'):\n",
2222
" subprocess.check_call([sys.executable, \"-m\", \"pip\", \"install\", \"--quiet\", package])"
2323
]
2424
},
@@ -28,9 +28,9 @@
2828
"metadata": {},
2929
"outputs": [],
3030
"source": [
31-
"from ipywidgets import Tab, SelectMultiple, IntSlider, FloatSlider, HTML, HBox, VBox, Output\n",
31+
"from ipywidgets import Tab, SelectMultiple, IntSlider, FloatSlider, HBox, VBox, Output\n",
3232
"from matplotlib import pyplot\n",
33-
"from IPython.display import display\n",
33+
"from IPython.display import display, clear_output\n",
3434
"import PyPartMC as ppmc"
3535
]
3636
},
@@ -39,32 +39,14 @@
3939
"execution_count": 4,
4040
"metadata": {},
4141
"outputs": [],
42-
"source": [
43-
"%matplotlib widget\n",
44-
"\n",
45-
"if \"google.colab\" in sys.modules:\n",
46-
" HACK = (\n",
47-
" \"<link\"\n",
48-
" ' rel=\"stylesheet\"'\n",
49-
" ' href=\"https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css\"'\n",
50-
" \"> \"\n",
51-
" )\n",
52-
" display(HTML(HACK))"
53-
]
54-
},
55-
{
56-
"cell_type": "code",
57-
"execution_count": 5,
58-
"metadata": {},
59-
"outputs": [],
6042
"source": [
6143
"gas_data_widget = SelectMultiple(options=(\"H2SO4\", \"HNO3\", \"HCl\", \"NH3\", \"NO\", \"NO2\"))\n",
6244
"gas_data_widget.value = gas_data_widget.options"
6345
]
6446
},
6547
{
6648
"cell_type": "code",
67-
"execution_count": 6,
49+
"execution_count": 5,
6850
"metadata": {},
6951
"outputs": [],
7052
"source": [
@@ -73,7 +55,7 @@
7355
},
7456
{
7557
"cell_type": "code",
76-
"execution_count": 7,
58+
"execution_count": 6,
7759
"metadata": {},
7860
"outputs": [],
7961
"source": [
@@ -83,7 +65,7 @@
8365
},
8466
{
8567
"cell_type": "code",
86-
"execution_count": 8,
68+
"execution_count": 7,
8769
"metadata": {},
8870
"outputs": [],
8971
"source": [
@@ -94,14 +76,20 @@
9476
" ax.set_ylim(param_y_widget.min, param_y_widget.max)\n",
9577
" line_x = ax.plot([param_x_widget.value]*2, ax.get_ylim())\n",
9678
" line_y = ax.plot(ax.get_xlim(), [param_y_widget.value]*2)\n",
97-
"\n",
98-
"param_x_widget.observe(lambda change: line_x[0].set_xdata([change.new]*2), 'value')\n",
99-
"param_y_widget.observe(lambda change: line_y[0].set_ydata([change.new]*2), 'value')"
79+
" pyplot.show()\n",
80+
" \n",
81+
"def plot_update():\n",
82+
" with preview_output:\n",
83+
" clear_output(wait=True)\n",
84+
" display(fig)\n",
85+
" \n",
86+
"param_x_widget.observe(lambda change: line_x[0].set_xdata([change.new]*2) or plot_update(), 'value')\n",
87+
"param_y_widget.observe(lambda change: line_y[0].set_ydata([change.new]*2) or plot_update(), 'value')"
10088
]
10189
},
10290
{
10391
"cell_type": "code",
104-
"execution_count": 9,
92+
"execution_count": 8,
10593
"metadata": {},
10694
"outputs": [],
10795
"source": [
@@ -122,13 +110,13 @@
122110
},
123111
{
124112
"cell_type": "code",
125-
"execution_count": 10,
113+
"execution_count": 9,
126114
"metadata": {},
127115
"outputs": [
128116
{
129117
"data": {
130118
"application/vnd.jupyter.widget-view+json": {
131-
"model_id": "c9630f899d514ecb9c13641d56706dde",
119+
"model_id": "3e2802d5172d42a791329ae152b6e12b",
132120
"version_major": 2,
133121
"version_minor": 0
134122
},
@@ -146,7 +134,7 @@
146134
},
147135
{
148136
"cell_type": "code",
149-
"execution_count": 11,
137+
"execution_count": 10,
150138
"metadata": {},
151139
"outputs": [
152140
{
@@ -163,7 +151,7 @@
163151
},
164152
{
165153
"cell_type": "code",
166-
"execution_count": 12,
154+
"execution_count": 11,
167155
"metadata": {},
168156
"outputs": [
169157
{

0 commit comments

Comments
 (0)
Please sign in to comment.