| [ Web Proxy ] |
| Viewing: https://matplotlib.org/stable/api/_as_gen/../../gallery/animation/../ticks/custom_ticker1.html | [Back] [Original] |
Section Navigation
fill_between with transparencyhisttype settingsplt.subplotsfloating_axes featuresNote
Go to the end to download the full example code.
The 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.
import matplotlib.pyplot as plt
def millions(x, pos):
"""The two arguments are the value and tick position."""
return f'${x*1e-6:1.1f}M'
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()
[custom ticker1]References
The use of the following functions, methods, classes and modules is shown in this example:
Copyright 20022012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 20122026 The Matplotlib development team.
Created using Sphinx 9.1.0.
Built from v3.11.2-1-g879ad8ebba.
Built with the PyData Sphinx Theme 0.16.1.
| Web Proxy Viewer | New URL | Original Page |