-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ticker.EngFormatter: allow offset #28495
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
facb403
ticker.ScalarFormatter: allow changing usetex like in EngFormatter
doronbehar 7cb3f33
ticker.EngFormatter: base upon ScalarFormatter
doronbehar bc85731
Fix small documentation issues from QuLogic's review
doronbehar 744b544
Small comment fixups from review
doronbehar 5eec9e1
test_ticker.py: small cleanups after review
doronbehar b0da1aa
ticker.py: small cleanups after review
doronbehar 8e34c06
ticker.ScalarFormatter: Fix type hints & document new attributes
doronbehar a02eb9a
engformatter_offset.rst: fix title
doronbehar b7c6f90
engformatter related small fixes
doronbehar b2c35fa
test_engformatter_offset_oom: parametrize center & noise directly
doronbehar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
``matplotlib.ticker.EngFormatter`` can computes offsets now | ||
----------------------------------------------------------- | ||
|
||
`matplotlib.ticker.EngFormatter` has gained the ability to show an offset text near the | ||
axis. Using logic shared with `matplotlib.ticker.ScalarFormatter`, it is capable of | ||
deciding whether the data qualifies having an offset and show it with an appropriate SI | ||
quantity prefix, and with the supplied ``unit``. | ||
|
||
To enable this new behavior, simply pass ``useOffset=True`` when you | ||
instantiate `matplotlib.ticker.EngFormatter`. See example | ||
:doc:`/gallery/ticks/engformatter_offset`. | ||
|
||
.. plot:: gallery/ticks/engformatter_offset.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Miscellaneous Changes | ||
--------------------- | ||
|
||
- The `matplotlib.ticker.ScalarFormatter` class has gained a new instantiating parameter ``usetex``. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
=================================================== | ||
SI prefixed offsets and natural order of magnitudes | ||
=================================================== | ||
|
||
`matplotlib.ticker.EngFormatter` is capable of computing a natural | ||
offset for your axis data, and presenting it with a standard SI prefix | ||
automatically calculated. | ||
|
||
Below is an examples of such a plot: | ||
|
||
""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
import matplotlib.ticker as mticker | ||
|
||
# Fixing random state for reproducibility | ||
np.random.seed(19680801) | ||
|
||
UNIT = "Hz" | ||
|
||
fig, ax = plt.subplots() | ||
ax.yaxis.set_major_formatter(mticker.EngFormatter( | ||
useOffset=True, | ||
unit=UNIT | ||
)) | ||
size = 100 | ||
measurement = np.full(size, 1e9) | ||
noise = np.random.uniform(low=-2e3, high=2e3, size=size) | ||
ax.plot(measurement + noise) | ||
plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.