Skip to content

Instantly share code, notes, and snippets.

@benrules2
Last active March 14, 2017 17:32
Show Gist options
  • Save benrules2/856d4151573a1408eac23da83851495f to your computer and use it in GitHub Desktop.
Save benrules2/856d4151573a1408eac23da83851495f to your computer and use it in GitHub Desktop.
Python N-Body Orbit Simulator
def plot_output(bodies, outfile = None):
fig = plot.figure()
colours = ['r','b','g','y','m','c']
ax = fig.add_subplot(1,1,1, projection='3d')
max_range = 0
for current_body in bodies:
max_dim = max(max(current_body["x"]),max(current_body["y"]),max(current_body["z"]))
if max_dim > max_range:
max_range = max_dim
ax.plot(current_body["x"], current_body["y"], current_body["z"], c = random.choice(colours), label = current_body["name"])
ax.set_xlim([-max_range,max_range])
ax.set_ylim([-max_range,max_range])
ax.set_zlim([-max_range,max_range])
ax.legend()
if outfile:
plot.savefig(outfile)
else:
plot.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment