Skip to content

Commit 57d2f2b

Browse files
committed
Update the non-featured version of the recipe, as requested by Cyrille
1 parent eab51c5 commit 57d2f2b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

notebooks/chapter09_numoptim/04_energy.ipynb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@
168168
},
169169
"outputs": [],
170170
"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",
171178
"def show_bar(P):\n",
172179
" plt.figure(figsize=(5,4));\n",
173180
" # Wall.\n",
@@ -180,7 +187,7 @@
180187
" # is proportional to the spring elongation.\n",
181188
" c = D[i,j] - L[i,j]\n",
182189
" 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",
184191
" # We plot the masses.\n",
185192
" plt.plot(P[[I,J],0], P[[I,J],1], 'ok',);\n",
186193
" # We configure the axes.\n",
@@ -338,7 +345,7 @@
338345
"name": "python",
339346
"nbconvert_exporter": "python",
340347
"pygments_lexer": "ipython3",
341-
"version": "3.4.2"
348+
"version": "3.4.3"
342349
}
343350
},
344351
"nbformat": 4,

0 commit comments

Comments
 (0)