Skip to content
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

Change LogFormatterExponent to consistently format negative exponents #2691

Merged
merged 4 commits into from Jan 13, 2014

Conversation

joferkington
Copy link
Contributor

Currently, using LogFormatterExponent results in inconsistently formatted labels for values less than one. Integer values greater than one are displayed as integers, while values below one are displayed using scientific notation.

For example, the following currently produces an unexpected result:

import matplotlib.pyplot as plt
from matplotlib.ticker import LogFormatterExponent

fig, ax = plt.subplots()
ax.loglog()
ax.axis([10**-5, 10**5, 10**-5, 10**5])
ax.xaxis.set_major_formatter(LogFormatterExponent())
plt.show()

figure_1


With this fix, values below one are consistently formatted:

figure_1

This change does arguably break backwards compatibility, but I think (?) the current behavior is unintentional.

@@ -50,6 +50,32 @@ def test_LogLocator():
test_value = np.array([0.5, 1., 2., 4., 8., 16., 32., 64., 128., 256.])
assert_almost_equal(loc.tick_values(1, 100), test_value)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing blank line here

@tacaswell
Copy link
Member

Except for the pep8 issues, this looks good to me.

return 1, 10

i = np.arange(-3, 4, dtype=float)
expected_result = ['-3', '-2', '-1', '0', '1', '2', '3']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to test small negative (and positive values) also.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pelson - Absolutely, thanks! I added more non-integer tests with multiple bases in 03af950.

@pelson
Copy link
Member

pelson commented Jan 7, 2014

👍 from me

@joferkington
Copy link
Contributor Author

@tacaswell & @pelson - Sorry for the delay! I fixed the PEP8 issues and added a few more tests. I also rebased the branch onto the current HEAD. If you'd like I can squash things back down to a single commit, as well.

tacaswell added a commit that referenced this pull request Jan 13, 2014
Change LogFormatterExponent to consistently format negative exponents
@tacaswell tacaswell merged commit 35e1823 into matplotlib:master Jan 13, 2014
@tacaswell
Copy link
Member

The travis failures are un-related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants