# Project Submission!

Thanks for viewing!
Any constructive criticism is absolutely welcome!
Although I’ve used 3D scatter plots to create positional maps before (I’m a material scientist by trade), I decided to push it and connect the plots into true constellations, which happened to be useful when viewing the 3D plot. I went for black backgrounds and golden points and lines to emphasize the context, which again is not something I have done so learning it was very useful.

``````from IPython import get_ipython

# %% [markdown]
# ## Project: Visualizing the Orion Constellation
#
# In this project you are Dr. Jillian Bellovary, a real-life astronomer for the Hayden Planetarium at the American Museum of Natural History. As an astronomer, part of your job is to study the stars. You've recently become interested in the constellation Orion, a collection of stars that appear in our night sky and form the shape of [Orion](https://en.wikipedia.org/wiki/Orion_(constellation)), a warrior God from ancient Greek mythology.
#
# As a researcher on the Hayden Planetarium team, you are in charge of visualizing the Orion constellation in 3D using the Matplotlib function `.scatter()`. To learn more about the `.scatter()` you can see the Matplotlib documentation [here](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.scatter.html).
#
# You will create a rotate-able visualization of the position of the Orion's stars and get a better sense of their actual positions. To achieve this, you will be mapping real data from outer space that maps the position of the stars in the sky
#
# The goal of the project is to understand spatial perspective. Once you visualize Orion in both 2D and 3D, you will be able to see the difference in the constellation shape humans see from earth versus the actual position of the stars that make up this constellation.
#
# <img src="https://upload.wikimedia.org/wikipedia/commons/9/91/Orion_constellation_with_star_labels.jpg" alt="Orion" style="width: 400px;"/>
#
#
# %% [markdown]
# ## 1. Set-Up
# The following set-up is new and specific to the project. It is very similar to the way you have imported Matplotlib in previous lessons.
#
# + Add `%matplotlib notebook` in the cell below. This is a new statement that you may not have seen before. It will allow you to be able to rotate your visualization in this jupyter notebook.
#
# + We will be using a subset of Matplotlib: `matplotlib.pyplot`. Import the subset as you have been importing it in previous lessons: `from matplotlib import pyplot as plt`
#
#
# + In order to see our 3D visualization, we also need to add this new line after we import Matplotlib:
# `from mpl_toolkits.mplot3d import Axes3D`
#

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

# %% [markdown]
# ## 2. Get familiar with real data
#
# Astronomers describe a star's position in the sky by using a pair of angles: declination and right ascension. Declination is similar to longitude, but it is projected on the celestian fear. Right ascension is known as the "hour angle" because it accounts for time of day and earth's rotaiton. Both angles are relative to the celestial equator. You can learn more about star position [here](https://en.wikipedia.org/wiki/Star_position).
#
# The `x`, `y`, and `z` lists below are composed of the x, y, z coordinates for each star in the collection of stars that make up the Orion constellation as documented in a paper by Nottingham Trent Univesity on "The Orion constellation as an installation" found [here](https://arxiv.org/ftp/arxiv/papers/1110/1110.3469.pdf).
#
# Spend some time looking at `x`, `y`, and `z`, does each fall within a range?

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

# %% [markdown]
# ## 3. Create a 2D Visualization
#
# Before we visualize the stars in 3D, let's get a sense of what they look like in 2D.
#
# Create a figure for the 2d plot and save it to a variable name `fig`. (hint: `plt.figure()`)
#
#
# Use the scatter [function](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.scatter.html) to visualize your `x` and `y` coordinates. (hint: `.scatter(x,y)`)
#
# Render your visualization. (hint: `plt.show()`)
#
# Does the 2D visualization look like the Orion constellation we see in the night sky? Do you recognize its shape in 2D? There is a curve to the sky, and this is a flat visualization, but we will visualize it in 3D in the next step to get a better sense of the actual star positions.

# %%
fig = plt.figure()
ax = fig.gca(projection = "3d")
sub = plt.subplot(111)
plt.scatter(x,y, color = "gold")
plt.plot(x, y, color = "gold")
plt.title("2D Plot (X vs Y) of the Orion Star Constellation")
sub.set_facecolor("black")
plt.xlabel("X Coordinate")
plt.ylabel("Y Coordinate")
plt.show()

# %% [markdown]
# ## 4. Create a 3D Visualization
#
# Create a figure for the 3D plot and save it to a variable name `fig_3d`. (hint: `plt.figure()`)
#
#
# Since this will be a 3D projection, we want to make to tell Matplotlib this will be a 3D plot.
#
# To add a 3D projection, you must include a the projection argument. It would look like this:
# ```py
# projection="3d"
# ```
#
#
#
# Since this visualization will be in 3D, we will need our third dimension. In this case, our `z` coordinate.
#
# Create a new variable `constellation3d` and call the scatter [function](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.scatter.html) with your `x`, `y` and `z` coordinates.
#
# Include `z` just as you have been including the other two axes. (hint: `.scatter(x,y,z)`)
#
# Render your visualization. (hint `plt.show()`.)
#

# %%
fig3d = plt.figure()
constellation3d = fig3d.add_subplot(1,1,1, projection = "3d")
constellation = constellation3d.scatter(x, y, z, marker = "s", color = "gold", linewidths = 6)
constellation3d.plot(x, y, z, color = "gold")
constellation3d.xaxis.pane.set_facecolor('black')
constellation3d.yaxis.pane.set_facecolor('black')
constellation3d.zaxis.pane.set_facecolor('black')
plt.show()
``````

Please note: I wasn’t sure how to upload this as a jupyter notebook so I exported it as pure python code. If someone could let me know how to get the notebook format uploaded I’d be happy to share it as I know that is the preference here.

Hello fellow Corey,

If you click on the file button on your notebook you can save as a notebook file. Then you can upload it to a github repository and post a link! I hope this is helpful.

1 Like

Brilliant!
Thanking you kindly for your help!
All the best,

Corey

Hello dear people, here is my constellation project, ready for improvment!
I tried to increase the size of the stars by adding s=50 in scatter function, but it did not work TypeError: scatter() got multiple values for argument ‘s’, can somebody explain me why?

Here is code:

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

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_2d = plt.figure()
plt.scatter(x,y, c=“orange”, marker="*")
plt.title(’ Orion Constellation’)
plt.xlabel(‘X coordinates’)
plt.ylabel(‘Y coordinates’)
ax.set_facecolor(‘xkcd:black’)
plt.show()

fig_3d = plt.figure()
constelation3d = plt.scatter(x,y,z, color=“orange”, marker="*", s=50)
plt.title(" 3D View of Orion Constellation")
plt.xlabel(“X axis”)
plt.ylabel(“Y axis”)
plt.show()