.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/text_labels_and_annotations/engineering_formatter.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_text_labels_and_annotations_engineering_formatter.py: ========================================= Labeling ticks using engineering notation ========================================= Use of the engineering Formatter. .. GENERATED FROM PYTHON SOURCE LINES 8-45 .. image-sg:: /gallery/text_labels_and_annotations/images/sphx_glr_engineering_formatter_001.png :alt: Full unit ticklabels, w/ default precision & space separator, SI-prefix only ticklabels, 1-digit precision & thin space separator :srcset: /gallery/text_labels_and_annotations/images/sphx_glr_engineering_formatter_001.png, /gallery/text_labels_and_annotations/images/sphx_glr_engineering_formatter_001_2_00x.png 2.00x :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from matplotlib.ticker import EngFormatter # Fixing random state for reproducibility prng = np.random.RandomState(19680801) # Create artificial data to plot. # The x data span over several decades to demonstrate several SI prefixes. xs = np.logspace(1, 9, 100) ys = (0.8 + 0.4 * prng.uniform(size=100)) * np.log10(xs)**2 # Figure width is doubled (2*6.4) to display nicely 2 subplots side by side. fig, (ax0, ax1) = plt.subplots(nrows=2, figsize=(7, 9.6)) for ax in (ax0, ax1): ax.set_xscale('log') # Demo of the default settings, with a user-defined unit label. ax0.set_title('Full unit ticklabels, w/ default precision & space separator') formatter0 = EngFormatter(unit='Hz') ax0.xaxis.set_major_formatter(formatter0) ax0.plot(xs, ys) ax0.set_xlabel('Frequency') # Demo of the options `places` (number of digit after decimal point) and # `sep` (separator between the number and the prefix/unit). ax1.set_title('SI-prefix only ticklabels, 1-digit precision & ' 'thin space separator') formatter1 = EngFormatter(places=1, sep="\N{THIN SPACE}") # U+2009 ax1.xaxis.set_major_formatter(formatter1) ax1.plot(xs, ys) ax1.set_xlabel('Frequency [Hz]') plt.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.423 seconds) .. _sphx_glr_download_gallery_text_labels_and_annotations_engineering_formatter.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: engineering_formatter.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: engineering_formatter.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_