.. only:: html
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here ` to download the full example code
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_gallery_ticks_and_spines_custom_ticker1.py:
==============
Custom Ticker1
==============
The new ticker code was designed to explicitly support user customized
ticking. The documentation of :mod:`matplotlib.ticker` 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.
.. code-block:: default
import matplotlib.pyplot as plt
money = [1.5e5, 2.5e6, 5.5e6, 2.0e7]
def millions(x, pos):
"""The two args are the value and tick position."""
return '${:1.1f}M'.format(x*1e-6)
fig, ax = plt.subplots()
# Use automatic FuncFormatter creation
ax.yaxis.set_major_formatter(millions)
ax.bar(['Bill', 'Fred', 'Mary', 'Sue'], money)
plt.show()
.. image:: /gallery/ticks_and_spines/images/sphx_glr_custom_ticker1_001.png
:alt: custom ticker1
:class: sphx-glr-single-img
------------
References
""""""""""
The use of the following functions, methods, classes and modules is shown
in this example:
.. code-block:: default
import matplotlib
matplotlib.pyplot.subplots
matplotlib.axis.Axis.set_major_formatter
matplotlib.ticker.FuncFormatter
.. _sphx_glr_download_gallery_ticks_and_spines_custom_ticker1.py:
.. only :: html
.. container:: sphx-glr-footer
:class: sphx-glr-footer-example
.. container:: sphx-glr-download sphx-glr-download-python
:download:`Download Python source code: custom_ticker1.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: custom_ticker1.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
Keywords: matplotlib code example, codex, python plot, pyplot
`Gallery generated by Sphinx-Gallery
`_