

.. _sphx_glr_gallery_userdemo_demo_ticklabel_alignment.py:


========================
Demo Ticklabel Alignment
========================





.. image:: /gallery/userdemo/images/sphx_glr_demo_ticklabel_alignment_001.png
    :align: center





.. code-block:: python



    import matplotlib.pyplot as plt
    import mpl_toolkits.axisartist as axisartist


    def setup_axes(fig, rect):
        ax = axisartist.Subplot(fig, rect)
        fig.add_subplot(ax)

        ax.set_yticks([0.2, 0.8])
        ax.set_yticklabels(["short", "loooong"])
        ax.set_xticks([0.2, 0.8])
        ax.set_xticklabels([r"$\frac{1}{2}\pi$", r"$\pi$"])

        return ax


    fig = plt.figure(1, figsize=(3, 5))
    fig.subplots_adjust(left=0.5, hspace=0.7)

    ax = setup_axes(fig, 311)
    ax.set_ylabel("ha=right")
    ax.set_xlabel("va=baseline")

    ax = setup_axes(fig, 312)
    ax.axis["left"].major_ticklabels.set_ha("center")
    ax.axis["bottom"].major_ticklabels.set_va("top")
    ax.set_ylabel("ha=center")
    ax.set_xlabel("va=top")

    ax = setup_axes(fig, 313)
    ax.axis["left"].major_ticklabels.set_ha("left")
    ax.axis["bottom"].major_ticklabels.set_va("bottom")
    ax.set_ylabel("ha=left")
    ax.set_xlabel("va=bottom")

    plt.show()

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



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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

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

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