

.. _sphx_glr_gallery_pylab_examples_custom_ticker1.py:


==============
Custom Ticker1
==============

The new ticker code was designed to explicitly support user customized
ticking.  The documentation
http://matplotlib.org/matplotlib.ticker.html details this
process.  That code defines a lot of preset tickers but was primarily
designed to be user extensible.

In this example a user defined function is used to format the ticks in
millions of dollars on the y axis




.. image:: /gallery/pylab_examples/images/sphx_glr_custom_ticker1_001.png
    :align: center





.. code-block:: python

    from matplotlib.ticker import FuncFormatter
    import matplotlib.pyplot as plt
    import numpy as np

    x = np.arange(4)
    money = [1.5e5, 2.5e6, 5.5e6, 2.0e7]


    def millions(x, pos):
        'The two args are the value and tick position'
        return '$%1.1fM' % (x*1e-6)

    formatter = FuncFormatter(millions)

    fig, ax = plt.subplots()
    ax.yaxis.set_major_formatter(formatter)
    plt.bar(x, money)
    plt.xticks(x, ('Bill', 'Fred', 'Mary', 'Sue'))
    plt.show()

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



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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

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

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