Skip to content

Commit 968ecce

Browse files
committed
a little nicer n-body draw()
1 parent 861aa33 commit 968ecce

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,19 @@ def draw(simulation, masses, colors=None, scale=5.):
319319
# ax.set_aspect('equal')
320320
321321
ax.set_title(f"we have {N} bodies over {nb_steps} steps")
322-
for step in range(nb_steps):
322+
# looping on bodies, instead of on steps,
323+
# so we can also plot each trajectory
324+
for body_index, color in enumerate(colors):
325+
mass = masses[body_index]
323326
ax.scatter(
324327
# the X's and Y's
325-
simulation[step, 0, :], simulation[step, 1, :],
328+
simulation[:, 0, body_index], simulation[:, 1, body_index],
326329
# marker size is actually an area
327-
c=colors, s=(masses*scale)**2,
330+
color=color, s=(mass*scale)**2,
331+
)
332+
ax.plot(
333+
simulation[:, 0, body_index], simulation[:, 1, body_index],
334+
color=color, alpha=0.5, linewidth=0.1
328335
)
329336
return ax
330337
```
-6.46 KB
Loading

0 commit comments

Comments
 (0)