.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_plotting_parallel.py:


Parallel Coordinate Plots
============================

Parallel coordinate plots are one way to visualise data relationships and clusters in
higher dimensional data. pyrolite now includes an implementation of this which allows
a handy quick exploratory visualisation.


.. code-block:: default

    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    import matplotlib.axes
    import pyrolite.plot
    import pyrolite.data.Aitchison








To start, let's load up an example dataset from Aitchison



.. code-block:: default

    df = pyrolite.data.Aitchison.load_coxite()
    comp = [
        i for i in df.columns if i not in ["Depth", "Porosity"]
    ]  # compositional data variables








.. code-block:: default

    ax = df.pyroplot.parallel()
    plt.show()



.. image:: /examples/plotting/images/sphx_glr_parallel_001.png
    :class: sphx-glr-single-img





By rescaling this using the mean and standard deviation, we can account for scale
differences between variables:



.. code-block:: default

    ax = df.pyroplot.parallel(rescale=True)
    plt.show()



.. image:: /examples/plotting/images/sphx_glr_parallel_002.png
    :class: sphx-glr-single-img





We can also use a centred-log transform for compositional data to reduce the effects
of spurious correlation:



.. code-block:: default

    from pyrolite.util.skl.transform import CLRTransform

    cmap = "inferno"
    compdata = df.copy()
    compdata[comp] = CLRTransform().transform(compdata[comp])
    ax = compdata.loc[:, comp].pyroplot.parallel(color_by=compdata.Depth.values, cmap=cmap)

    # we can add a meaningful colorbar to indicate one variable also, here Depth
    sm = plt.cm.ScalarMappable(cmap=cmap)
    sm.set_array(df.Depth)
    plt.colorbar(sm)
    plt.show()



.. image:: /examples/plotting/images/sphx_glr_parallel_003.png
    :class: sphx-glr-single-img






.. code-block:: default

    ax = compdata.loc[:, comp].pyroplot.parallel(
        rescale=True, color_by=compdata.Depth.values, cmap=cmap
    )
    plt.colorbar(sm)
    plt.show()



.. image:: /examples/plotting/images/sphx_glr_parallel_004.png
    :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  1.124 seconds)


.. _sphx_glr_download_examples_plotting_parallel.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example


  .. container:: binder-badge

    .. image:: https://mybinder.org/badge_logo.svg
      :target: https://mybinder.org/v2/gh/morganjwilliams/pyrolite/develop?filepath=docs/source/examples/plotting/parallel.ipynb
      :width: 150 px


  .. container:: sphx-glr-download sphx-glr-download-python

     :download:`Download Python source code: parallel.py <parallel.py>`



  .. container:: sphx-glr-download sphx-glr-download-jupyter

     :download:`Download Jupyter notebook: parallel.ipynb <parallel.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
