

.. _sphx_glr_gallery_axes_grid1_parasite_simple2.py:


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





.. image:: /gallery/axes_grid1/images/sphx_glr_parasite_simple2_001.png
    :align: center





.. code-block:: python

    import matplotlib.transforms as mtransforms
    import matplotlib.pyplot as plt
    from mpl_toolkits.axes_grid1.parasite_axes import SubplotHost

    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 = SubplotHost(fig, 1, 1, 1, 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)
    ax_pm.set_viewlim_mode("transform")

    fig.add_subplot(ax_kms)

    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.draw()
    plt.show()

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



.. only :: html

 .. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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


.. only:: html

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

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