-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Change LogFormatterExponent to consistently format negative exponents #2691
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
Changes from all commits
f3d97b9
1eb8aca
03af950
bad39f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,38 @@ def test_LogLocator(): | |
assert_almost_equal(loc.tick_values(1, 100), test_value) | ||
|
||
|
||
def test_LogFormatterExponent(): | ||
class FakeAxis(object): | ||
"""Allow Formatter to be called without having a "full" plot set up.""" | ||
def get_view_interval(self): | ||
return 1, 10 | ||
|
||
i = np.arange(-3, 4, dtype=float) | ||
expected_result = ['-3', '-2', '-1', '0', '1', '2', '3'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be nice to test small negative (and positive values) also. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
for base in [2, 5, 10, np.pi, np.e]: | ||
formatter = mticker.LogFormatterExponent(base=base) | ||
formatter.axis = FakeAxis() | ||
vals = base**i | ||
labels = [formatter(x, pos) for (x, pos) in zip(vals, i)] | ||
nose.tools.assert_equal(labels, expected_result) | ||
|
||
# Should be a blank string for non-integer powers if labelOnlyBase=True | ||
formatter = mticker.LogFormatterExponent(base=10, labelOnlyBase=True) | ||
formatter.axis = FakeAxis() | ||
nose.tools.assert_equal(formatter(10**0.1), '') | ||
|
||
# Otherwise, non-integer powers should be nicely formatted | ||
locs = np.array([0.1, 0.00001, np.pi, 0.2, -0.2, -0.00001]) | ||
i = range(len(locs)) | ||
expected_result = ['0.1', '1e-05', '3.14', '0.2', '-0.2', '-1e-05'] | ||
for base in [2, 5, 10, np.pi, np.e]: | ||
formatter = mticker.LogFormatterExponent(base, labelOnlyBase=False) | ||
formatter.axis = FakeAxis() | ||
vals = base**locs | ||
labels = [formatter(x, pos) for (x, pos) in zip(vals, i)] | ||
nose.tools.assert_equal(labels, expected_result) | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tacaswell - Thanks! Apparently I wasn't paying very much attention when I pushed this! |
||
def test_use_offset(): | ||
for use_offset in [True, False]: | ||
with matplotlib.rc_context({'axes.formatter.useoffset': use_offset}): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing blank line here