Orion Constellation

Here’s my code! Couldn’t figure out how to label the Z-axis, though…

%matplotlib notebook
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# Orion
x = [-0.41, 0.57, 0.07, 0.00, -0.29, -0.32,-0.50,-0.23, -0.23]
y = [4.12, 7.71, 2.36, 9.10, 13.35, 8.13, 7.19, 13.25,13.43]
z = [2.06, 0.84, 1.56, 2.07, 2.36, 1.72, 0.66, 1.25,1.38]

fig = plt.figure()

fig.add_subplot(1, 1, 1)
plt.scatter(x, y, marker='*', label='Orion\'s stars', )
plt.title('2D Star Plot')
plt.xlabel('x coordinates')
plt.ylabel('y coordinates')
plt.grid()
plt.legend()

plt.show()

fig_3d = plt.figure()
fig_3d.add_subplot(1, 1, 1, projection='3d')

constellation3d = plt.scatter(x, y, z, marker='*', label='Orion\'s stars')
plt.title('3D Star Plot')
plt.xlabel('x coordinates')
plt.ylabel('y coordinates')
plt.legend()

plt.show()

You could push this notebook to a GH repo so people could see the results of your visualizations.

You have to use the scatterplot method for the 3d axis. As it is now, you’re using the 2-d scatterplot method.

For example, see:

Summary
fig3d = plt.figure()
ax3D = fig3d.add_subplot(1,1,1, projection="3d")
ax3D.set_facecolor('black')
ax3D.grid(False)
ax3D.scatter(x,y,z, c='gold', marker = '*', s= 100)

plt.title('3D Constellation: Orion')

#gets rid of panes
ax3D.w_xaxis.set_pane_color((0, 0, 0, 1.0))
ax3D.w_yaxis.set_pane_color((0, 0, 0, 1.0))
ax3D.w_zaxis.set_pane_color((0, 0, 0, 1.0))
plt.show()

Might want to peruse the forums here to see how others have done the project too.

Here’s the documentation:

https://matplotlib.org/stable/api/_as_gen/mpl_toolkits.mplot3d.axes3d.Axes3D.html

1 Like

Thanks for the feedback! I’m very rusty, and have yet to learn how to use GitHub. Would you recommend I pause DataViz until I complete the GitHub course?

Got it! I was wondering why they all ended up on the same plane. I’ll give the forums a browse and implement your code.

P.S.: How do I give credit for code? Should I make like a bibliography type of deal?

1 Like

Isn’t there a section on GitHub in that course? (I cannot recall).
Did you use Jupyter Notebook for this project?

You could always create a GH account/profile and then create some repositories and upload your Jupyter Notebooks to GH. (it’s a fairly quick process. See: GitHub Documentation)

You know, that’s a good question. I mean, are you directly copying someone else’s code (technically, you shouldn’t)? I guess you could always say, “inspired by so and so’s project/code”. I mean, we’re all using the same methods for python, just in a different order or way, creatively. The code I pasted above is mine and just my preference of how I wanted to do the project (black background, no grid lines, no panes, etc.). Everyone is different and will add their own spin to the projects…

The docs are useful…there’s all kinds of parameters one can add for 3D plots to customize them.

1 Like