|
168 | 168 | },
|
169 | 169 | "outputs": [],
|
170 | 170 | "source": [
|
| 171 | + "def spring_color_map(c):\n", |
| 172 | + " min_c, max_c = -0.00635369422326, 0.00836362559722\n", |
| 173 | + " ratio = (max_c-c) / (max_c-min_c)\n", |
| 174 | + " color = plt.cm.coolwarm(ratio)\n", |
| 175 | + " shading = np.sqrt(abs(ratio-0.5)*2)\n", |
| 176 | + " return (shading*color[0], shading*color[1], shading*color[2], color[3])\n", |
| 177 | + "\n", |
171 | 178 | "def show_bar(P):\n",
|
172 | 179 | " plt.figure(figsize=(5,4));\n",
|
173 | 180 | " # Wall.\n",
|
|
180 | 187 | " # is proportional to the spring elongation.\n",
|
181 | 188 | " c = D[i,j] - L[i,j]\n",
|
182 | 189 | " plt.plot(P[[i,j],0], P[[i,j],1], \n",
|
183 |
| - " lw=2, color=plt.cm.copper(c*150));\n", |
| 190 | + " lw=2, color=spring_color_map(c));\n", |
184 | 191 | " # We plot the masses.\n",
|
185 | 192 | " plt.plot(P[[I,J],0], P[[I,J],1], 'ok',);\n",
|
186 | 193 | " # We configure the axes.\n",
|
|
338 | 345 | "name": "python",
|
339 | 346 | "nbconvert_exporter": "python",
|
340 | 347 | "pygments_lexer": "ipython3",
|
341 |
| - "version": "3.4.2" |
| 348 | + "version": "3.4.3" |
342 | 349 | }
|
343 | 350 | },
|
344 | 351 | "nbformat": 4,
|
|
0 commit comments