Matplotlib: Constellation project - feedback please :D

Hi there,

I’ve just completed the Constellation project from the Data Science Career path.

Do you agree with my findings?

Let me know what you think and many thanks in advance,
Martin

%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]

#All 3 lists fall in the same range of 9: range(9).

#2D Visualization
#Creating the 2D scatter graph, x against y
plt.scatter(x, y, color=‘green’)
plt.title(‘2D visualization of the Orion constellation’)
plt.xlabel(‘Declination’)
plt.ylabel(‘Right Ascension’)
plt.show()

#The 2D visalization does not provide us with a good picture of the Orion constellation. It is quite difficult to get an idea of what it represents.

#3D visualization
plt.close(‘all’)
#Defining the figure for our 3D visualization
fig = plt.figure(figsize=(6, 5))
ax = fig.add_subplot(1,1,1,projection=‘3d’)
#Defining my constellation 3d variable but to be fair, I prefer working with plt.scatter() alone
#constellation_3d = plt.scatter(x, y, z)
plt.scatter(x, y, z, color=‘purple’)
#Setting labels thanks to ax.set_xlabel() and a title
ax.set_xlabel(‘Declination’)
ax.set_ylabel(‘Right ascension’)
ax.set_zlabel(‘Celestial equator’)
plt.title(‘Orion Constellation’)
plt.show()

#the labels of my axis might be wrong but I thought it would be fun to play around with them
#Thanks in advance for your review

Congrats on finishing up, if you’re looking for a little critique-

Whilst using plt.scatter might be preferable to you, the standard matplotlib.pyplot.scatter function is only a 2D scatter function (all those points are on the same xy plane at z=0.0 ). You need to be using the scatter method of the 3d axis itself in order to actually plot the z-values, e.g. ax3d.scatter(x, y, z, s=30, marker... etc.) . See the docs for info-
https://matplotlib.org/3.3.0/api/_as_gen/mpl_toolkits.mplot3d.axes3d.Axes3D.html#mpl_toolkits.mplot3d.axes3d.Axes3D.scatter

You are correct that the labels aren’t quite right. Based on the original paper the values for x, y, z are in fact Cartesian co-ordinates, not right angle, declination and (celestial equator?) so units might be a more appropriate label for each of them.

Hey!

Thanks a lot for you review, very useful feedback.

Martin