|
18 | 18 | "outputs": [],
|
19 | 19 | "source": [
|
20 | 20 | "import subprocess\n",
|
21 |
| - "for package in ('ipywidgets', 'matplotlib', 'ipympl'):\n", |
| 21 | + "for package in ('ipywidgets', 'matplotlib'):\n", |
22 | 22 | " subprocess.check_call([sys.executable, \"-m\", \"pip\", \"install\", \"--quiet\", package])"
|
23 | 23 | ]
|
24 | 24 | },
|
|
28 | 28 | "metadata": {},
|
29 | 29 | "outputs": [],
|
30 | 30 | "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", |
32 | 32 | "from matplotlib import pyplot\n",
|
33 |
| - "from IPython.display import display\n", |
| 33 | + "from IPython.display import display, clear_output\n", |
34 | 34 | "import PyPartMC as ppmc"
|
35 | 35 | ]
|
36 | 36 | },
|
|
39 | 39 | "execution_count": 4,
|
40 | 40 | "metadata": {},
|
41 | 41 | "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": [], |
60 | 42 | "source": [
|
61 | 43 | "gas_data_widget = SelectMultiple(options=(\"H2SO4\", \"HNO3\", \"HCl\", \"NH3\", \"NO\", \"NO2\"))\n",
|
62 | 44 | "gas_data_widget.value = gas_data_widget.options"
|
63 | 45 | ]
|
64 | 46 | },
|
65 | 47 | {
|
66 | 48 | "cell_type": "code",
|
67 |
| - "execution_count": 6, |
| 49 | + "execution_count": 5, |
68 | 50 | "metadata": {},
|
69 | 51 | "outputs": [],
|
70 | 52 | "source": [
|
|
73 | 55 | },
|
74 | 56 | {
|
75 | 57 | "cell_type": "code",
|
76 |
| - "execution_count": 7, |
| 58 | + "execution_count": 6, |
77 | 59 | "metadata": {},
|
78 | 60 | "outputs": [],
|
79 | 61 | "source": [
|
|
83 | 65 | },
|
84 | 66 | {
|
85 | 67 | "cell_type": "code",
|
86 |
| - "execution_count": 8, |
| 68 | + "execution_count": 7, |
87 | 69 | "metadata": {},
|
88 | 70 | "outputs": [],
|
89 | 71 | "source": [
|
|
94 | 76 | " ax.set_ylim(param_y_widget.min, param_y_widget.max)\n",
|
95 | 77 | " line_x = ax.plot([param_x_widget.value]*2, ax.get_ylim())\n",
|
96 | 78 | " 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')" |
100 | 88 | ]
|
101 | 89 | },
|
102 | 90 | {
|
103 | 91 | "cell_type": "code",
|
104 |
| - "execution_count": 9, |
| 92 | + "execution_count": 8, |
105 | 93 | "metadata": {},
|
106 | 94 | "outputs": [],
|
107 | 95 | "source": [
|
|
122 | 110 | },
|
123 | 111 | {
|
124 | 112 | "cell_type": "code",
|
125 |
| - "execution_count": 10, |
| 113 | + "execution_count": 9, |
126 | 114 | "metadata": {},
|
127 | 115 | "outputs": [
|
128 | 116 | {
|
129 | 117 | "data": {
|
130 | 118 | "application/vnd.jupyter.widget-view+json": {
|
131 |
| - "model_id": "c9630f899d514ecb9c13641d56706dde", |
| 119 | + "model_id": "3e2802d5172d42a791329ae152b6e12b", |
132 | 120 | "version_major": 2,
|
133 | 121 | "version_minor": 0
|
134 | 122 | },
|
|
146 | 134 | },
|
147 | 135 | {
|
148 | 136 | "cell_type": "code",
|
149 |
| - "execution_count": 11, |
| 137 | + "execution_count": 10, |
150 | 138 | "metadata": {},
|
151 | 139 | "outputs": [
|
152 | 140 | {
|
|
163 | 151 | },
|
164 | 152 | {
|
165 | 153 | "cell_type": "code",
|
166 |
| - "execution_count": 12, |
| 154 | + "execution_count": 11, |
167 | 155 | "metadata": {},
|
168 | 156 | "outputs": [
|
169 | 157 | {
|
|
0 commit comments