.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/ticks/custom_ticker1.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. 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_custom_ticker1.py: ============= Custom Ticker ============= The :mod:`matplotlib.ticker` module defines many preset tickers, but was primarily designed for extensibility, i.e., to support user customized ticking. In this example, a user defined function is used to format the ticks in millions of dollars on the y axis. .. GENERATED FROM PYTHON SOURCE LINES 12-28 .. code-block:: default import matplotlib.pyplot as plt def millions(x, pos): """The two arguments are the value and tick position.""" return '${:1.1f}M'.format(x*1e-6) fig, ax = plt.subplots() # set_major_formatter internally creates a FuncFormatter from the callable. ax.yaxis.set_major_formatter(millions) money = [1.5e5, 2.5e6, 5.5e6, 2.0e7] ax.bar(['Bill', 'Fred', 'Mary', 'Sue'], money) plt.show() .. image-sg:: /gallery/ticks/images/sphx_glr_custom_ticker1_001.png :alt: custom ticker1 :srcset: /gallery/ticks/images/sphx_glr_custom_ticker1_001.png, /gallery/ticks/images/sphx_glr_custom_ticker1_001_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 29-35 .. admonition:: References The use of the following functions, methods, classes and modules is shown in this example: - `matplotlib.axis.Axis.set_major_formatter` .. _sphx_glr_download_gallery_ticks_custom_ticker1.py: .. only:: html .. container:: sphx-glr-footer 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 `Gallery generated by Sphinx-Gallery `_