
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/axes_grid1/parasite_simple2.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_axes_grid1_parasite_simple2.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_axes_grid1_parasite_simple2.py:


================
Parasite Simple2
================

.. GENERATED FROM PYTHON SOURCE LINES 7-46

.. code-block:: Python

    import matplotlib.pyplot as plt

    import matplotlib.transforms as mtransforms
    from mpl_toolkits.axes_grid1.parasite_axes import HostAxes

    obs = [["01_S1", 3.88, 0.14, 1970, 63],
           ["01_S4", 5.6, 0.82, 1622, 150],
           ["02_S1", 2.4, 0.54, 1570, 40],
           ["03_S1", 4.1, 0.62, 2380, 170]]


    fig = plt.figure()

    ax_kms = fig.add_subplot(axes_class=HostAxes, aspect=1)

    # angular proper motion("/yr) to linear velocity(km/s) at distance=2.3kpc
    pm_to_kms = 1./206265.*2300*3.085e18/3.15e7/1.e5

    aux_trans = mtransforms.Affine2D().scale(pm_to_kms, 1.)
    ax_pm = ax_kms.twin(aux_trans)

    for n, ds, dse, w, we in obs:
        time = ((2007 + (10. + 4/30.)/12) - 1988.5)
        v = ds / time * pm_to_kms
        ve = dse / time * pm_to_kms
        ax_kms.errorbar([v], [w], xerr=[ve], yerr=[we], color="k")


    ax_kms.axis["bottom"].set_label("Linear velocity at 2.3 kpc [km/s]")
    ax_kms.axis["left"].set_label("FWHM [km/s]")
    ax_pm.axis["top"].set_label(r"Proper Motion [$''$/yr]")
    ax_pm.axis["top"].label.set_visible(True)
    ax_pm.axis["right"].major_ticklabels.set_visible(False)

    ax_kms.set_xlim(950, 3700)
    ax_kms.set_ylim(950, 3100)
    # xlim and ylim of ax_pms will be automatically adjusted.

    plt.show()


.. _sphx_glr_download_gallery_axes_grid1_parasite_simple2.py:

.. only:: html

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

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

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

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

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: parasite_simple2.zip <parasite_simple2.zip>`


.. only:: html

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

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