Orion Constellation Project: What's wrong with my z-axis?

Hello Coders,

After visualizing Orion, I wanted to try to create a visualization of the Ursa Major constellation, as I was named after one of the stars in it (Talita :star_struck:). I was inspired by @camb5, who made a great visualization of Leo (their post here: Orion Constellation Project).

I’m having trouble with my z-axis, though. My 3d scatter plot appears flat, like I’m rotating around a 2d scatter plot. Why is this, when my data for the z-axis has a wide range? Also, the data points in the 3d plot are dots of varying sizes – I don’t know why. Can anyone provide some insight?

Thanks for checking my project out!

#Set-Up
%matplotlib notebook
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# Ursa Major Data
x_uma = [8.5, 9.52, 11.5, 12.25, 12.9, 13.38, 13.78, 11.88, 11.02, 9.83, 9.53, 8.98, 9.05, 11.77, 11.15, 10.37, 10.28, 11.3]
y_uma = [60.72, 63.05, 61.75, 57.02, 55.95, 54.92, 49.3, 53.68, 56.37, 59.03, 51.67, 48.03, 47.15, 47.77, 44.48, 41.48, 42.9, 33.08]
z_uma = [197.2, 76.8, 122.8, 81, 82.5, 81.5, 103.9, 83.1, 79.7, 112.1, 45.3, 46.2, 358.2, 193.2, 154.9, 230.2, 137.4, 23.7]

# Ursa Major 2D Visualization
fig_uma = plt.figure()
fig_uma.add_subplot(1, 1, 1)
plt.scatter(x_uma,y_uma, color='purple')
plt.title('Ursa Major Constellation in 2D', color='purple')
plt.xlabel('Projected Right Ascension')
plt.ylabel('Projected Declination')
plt.show()

# Ursa Major 3D Visualization
fig_uma_3d = plt.figure()
ax_uma = fig_uma_3d.add_subplot(1,1,1,projection='3d')
uma_constellation3d = plt.scatter(x_uma,y_uma,z_uma, color='purple')
plt.title('Ursa Major Constellation in 3D', color='purple')
ax_uma.set_xlabel('Projected Right Ascension')
ax_uma.set_ylabel('Projected Declination')
ax_uma.set_zlabel('Distance (light years)')
plt.show()

2d_ursa 3d_ursa_angle 3d_ursa_flat

Nice one, it’s always good to get more practice with extra datasets and even more so when it’s with something awesome like stellar constellations.

As for the unusual plotting, the standard matplotlib.pyplot.scatter() function treats the third argument as the marker size/scale rather than the z-position (this is how it operates for standard 2D plots). In this instance you want to ensure that you’re calling the .scatter() method of the 3d axis object, i.e. ax_uma.scatter() because it’s a similar but not identical method that is an attrbiute of the Axes3D object.

1 Like

@tgrtim That did it, thank you!!

3d_ursa_fixed

1 Like