.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/table/scatter.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_table_scatter.py: .. sectionauthor:: Duncan Macleod .. currentmodule:: gwpy.table Plotting an `EventTable` in a scatter ##################################### We can use GWpy's `EventTable` to download the catalogue of gravitational-wave detections, and create a scatter plot to investigate the mass distribution of events. .. GENERATED FROM PYTHON SOURCE LINES 32-34 First, we can download the ``'GWTC-1-confident'`` catalogue using :meth:`EventTable.fetch_open_data`: .. GENERATED FROM PYTHON SOURCE LINES 34-46 .. code-block:: Python from gwpy.table import EventTable events = EventTable.fetch_open_data( "GWTC", columns=( "mass_1_source", "mass_2_source", "luminosity_distance", "network_matched_filter_snr", ), ) .. GENERATED FROM PYTHON SOURCE LINES 47-49 We can now make a scatter plot by specifying the x- and y-axis columns, and (optionally) the colour: .. GENERATED FROM PYTHON SOURCE LINES 49-57 .. code-block:: Python plot = events.scatter( "mass_1_source", "mass_2_source", color="network_matched_filter_snr", ) plot.colorbar(label="Signal-to-noise ratio (SNR)") plot.show() .. image-sg:: /examples/table/images/sphx_glr_scatter_001.png :alt: scatter :srcset: /examples/table/images/sphx_glr_scatter_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 58-61 We can similarly plot how the total event mass is distributed with distance. First we have to build the total mass (``'mtotal'``) column from the component masses: .. GENERATED FROM PYTHON SOURCE LINES 61-67 .. code-block:: Python events.add_column( events["mass_1_source"] + events["mass_2_source"], name="mtotal" ) .. GENERATED FROM PYTHON SOURCE LINES 68-69 and now can make a new scatter plot: .. GENERATED FROM PYTHON SOURCE LINES 69-72 .. code-block:: Python plot = events.scatter("luminosity_distance", "mtotal") plot.show() .. image-sg:: /examples/table/images/sphx_glr_scatter_002.png :alt: scatter :srcset: /examples/table/images/sphx_glr_scatter_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.138 seconds) .. _sphx_glr_download_examples_table_scatter.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: scatter.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: scatter.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: scatter.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_