In this notebook, we will visualize the table of confirmed exoplanets from the NASA Exoplanet Archive (as of 30th September 2019), and we will take a look at some of the more advanced features of tabular data visualization.
import os
from astropy.table import Table
exoplanets = Table.read(os.path.join('data', 'planets_2019.09.30_16.25.03.votable'))
and we take a look at the first five rows to familiarize ourselves with the data:
exoplanets[:5]
from pywwt.jupyter import WWTJupyterWidget
and we use this class to create the pywwt "widget". Crucially, the second line (containing just wwt
) is needed to insert the widget into the notebook, and not just assign it to a variable.
wwt = WWTJupyterWidget()
wwt
If you're using JupyterLab and not just a plain Jupyter notebook, you can move the WWT view to a separate window pane. This is extremely useful since it lets you keep on typing code without scrolling WWT out of view. Here's how you do that:
If you don't get a menu when you right-click, or the menu doesn't look like the one pictured, you are using a plain Jupyter notebook and will have to scroll back and forth. See the First Steps notebook for more information and troubleshooting tips if you don’t get a viewer at all.
We are now ready to add the data to WWT. We start off by calling add_table_layer
to create the layer:
layer = wwt.layers.add_table_layer(exoplanets)
By default the points are quite small, so we can enlarge them:
layer.size_scale = 50
You should now see points appear in the widget above. Have a look around and see what the distribution of these confirmed exoplanets is on the sky. For example, you can use the following to point the view at the Kepler field:
from astropy import units as u
from astropy.coordinates import SkyCoord
wwt.center_on_coordinates(SkyCoord(76.32, 13.5, unit='deg', frame='galactic'), fov=20 * u.deg)
All the points are currently white, but you can also choose to color code points by one of the other attributes. For example, we can color code the points by effective temperature of the parent star:
layer.cmap_att = 'st_teff'
The cmap_vmin
and cmap_vmax
properties can be used to specify which values should be used as the extremes for the colorbar:
layer.cmap_vmin = 5000
layer.cmap_vmax = 8000
and finally the colormap can be set using the cmap
attribute, which takes either the name of a Matplotlib colormap or a Matplotlib colormap object:
layer.cmap = 'RdYlBu'
We can also scale the size of the points by one of the attributes — for example by the mass of the planet, and similarly we can set lower and upper values for the scaling:
layer.size_att = 'pl_bmassj'
layer.size_vmin = 0
layer.size_vmax = 30
Luckily, the exoplanet catalog contains Gaia distances to most of the planetary systems, so we can now tell the layer about the third dimension:
layer.alt_att = 'gaia_dist'
layer.alt_type = 'distance'
Finally we can switch PyWWT to 3D mode and explore the spatial distribution of the systems:
wwt.set_view('solar system')
Start zooming out, with a two finger scroll, using your mouse wheel, or by pressing 'x'. Some of the larger points dominate the view, so we can turn off the scaling by size:
layer.size_att = ''
Keep on zooming out until you can see (an artist’s rendering of) the plane of the Milky Way. At this point, you should see a cone of systems which corresponds to those discovered in the original Kepler field!
You may notice that some points appear and disappear as you rotate around. To avoid this effect, set the following option:
layer.far_side_visible = True
When this option is False
(the default), points on the other side of the Sun (or the reference object being used for plotting) are hidden — this is useful when plotting on e.g. planets and the Sun, but not when looking at this kind of data.
To see how to plot a data table that contains a time axis, check out the GRBs Over Time tutorial.