Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Reword custom_ticker1 example. #21019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions examples/ticks/custom_ticker1.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
"""
==============
Custom Ticker1
==============
=============
Custom Ticker
=============

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.
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
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

money = [1.5e5, 2.5e6, 5.5e6, 2.0e7]
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()
# Use automatic FuncFormatter creation
# 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()

Expand All @@ -33,6 +32,4 @@ def millions(x, pos):
# The use of the following functions, methods, classes and modules is shown
# in this example:
#
# - `matplotlib.pyplot.subplots`
# - `matplotlib.axis.Axis.set_major_formatter`
# - `matplotlib.ticker.FuncFormatter`