Skip to content

Commit 861aa33

Browse files
committed
n-body cosmetic improvement, larger dots
1 parent 13fc5ad commit 861aa33

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

notebooks/numpy-tps/n-body/.teacher/README-n-body-corrige-nb.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,40 +285,47 @@ si j'avais voulu implémenter 2.b il faudrait tripoter un peu plus nos interface
285285
```{code-cell} ipython3
286286
# votre code
287287
288-
def draw(simulation, masses, colors=None):
288+
def draw(simulation, masses, colors=None, scale=10.):
289289
"""
290290
takes as input the result of simulate() above,
291291
and draws the nb_steps positions of each of the N bodies
292292
ideally it should return a matplotlib Axes object
293293
294294
one can provide a collection of N colors to use for each body
295295
if not provided this is randomized
296+
297+
also the optional scale parameter is used as a constant
298+
multiplier to obtain the final size of each dot on the figure
296299
"""
297300
pass
298301
```
299302

300303
```{code-cell} ipython3
301304
# prune-cell
302305
303-
def draw(simulation, masses, colors=None):
306+
def draw(simulation, masses, colors=None, scale=5.):
304307
305308
nb_steps, _, N = simulation.shape
306309
# use colors if provided, else randomize
307310
colors = (colors if colors is not None
308311
# not too dark
309312
else np.random.uniform(0.3, 1., size=(N, 3)))
310313
311-
# create a figure and its axes
314+
# create a figure and its axes
312315
fig, ax = plt.subplots()
313316
314317
# not really needed but may come in handy though
315318
# ax.axis("off")
316319
# ax.set_aspect('equal')
317320
318-
319321
ax.set_title(f"we have {N} bodies over {nb_steps} steps")
320322
for step in range(nb_steps):
321-
ax.scatter(simulation[step, 0, :], simulation[step, 1, :], c=colors, s=masses)
323+
ax.scatter(
324+
# the X's and Y's
325+
simulation[step, 0, :], simulation[step, 1, :],
326+
# marker size is actually an area
327+
c=colors, s=(masses*scale)**2,
328+
)
322329
return ax
323330
```
324331

notebooks/numpy-tps/n-body/README-n-body-nb.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,17 @@ si j'avais voulu implémenter 2.b il faudrait tripoter un peu plus nos interface
216216
```{code-cell} ipython3
217217
# votre code
218218
219-
def draw(simulation, masses, colors=None):
219+
def draw(simulation, masses, colors=None, scale=10.):
220220
"""
221221
takes as input the result of simulate() above,
222222
and draws the nb_steps positions of each of the N bodies
223223
ideally it should return a matplotlib Axes object
224224
225225
one can provide a collection of N colors to use for each body
226226
if not provided this is randomized
227+
228+
also the optional scale parameter is used as a constant
229+
multiplier to obtain the final size of each dot on the figure
227230
"""
228231
pass
229232
```
12.2 KB
Loading

0 commit comments

Comments
 (0)