Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

FIX: formatting in LogFormatterExponent #5594

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 3 commits into from
Dec 14, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
FIX: formatting in LogFormatterExponent
The scale passed to the `pprint_val` method needs to also be
scaled by the log so that the range used to format the tick labels
matches the actual range of the tick labels (not the underlying values).

reported via http://stackoverflow.com/questions/33975758/matplotlib-logformatterexponent-e-in-the-exponent-labels-of-cbar
  • Loading branch information
tacaswell committed Dec 1, 2015
commit 7e3ef7dc2095852fbd3a668c4a0d3285a63e6ee3
33 changes: 23 additions & 10 deletions 33 lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,28 @@ def test_SymmetricalLogLocator_set_params():
nose.tools.assert_equal(sym.numticks, 8)


def _logfe_helper(formatter, base, locs, i, expected_result):
vals = base**locs
labels = [formatter(x, pos) for (x, pos) in zip(vals, i)]
nose.tools.assert_equal(labels, expected_result)


def test_LogFormatterExponent():
class FakeAxis(object):
"""Allow Formatter to be called without having a "full" plot set up."""
def __init__(self, vmin=1, vmax=10):
self.vmin = vmin
self.vmax = vmax

def get_view_interval(self):
return 1, 10
return self.vmin, self.vmax

i = np.arange(-3, 4, dtype=float)
expected_result = ['-3', '-2', '-1', '0', '1', '2', '3']
for base in [2, 5, 10, np.pi, np.e]:
for base in [2, 5.0, 10.0, 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)
formatter.axis = FakeAxis(1, base**4)
yield _logfe_helper, formatter, base, i, i, expected_result

# Should be a blank string for non-integer powers if labelOnlyBase=True
formatter = mticker.LogFormatterExponent(base=10, labelOnlyBase=True)
Expand All @@ -185,10 +193,15 @@ def get_view_interval(self):
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)
formatter.axis = FakeAxis(1, base**10)
yield _logfe_helper, formatter, base, locs, i, expected_result

expected_result = ['3', '5', '12', '42']
locs = np.array([3, 5, 12, 42], dtype='float')
for base in [2, 5.0, 10.0, np.pi, np.e]:
formatter = mticker.LogFormatterExponent(base, labelOnlyBase=False)
formatter.axis = FakeAxis(1, base**50)
yield _logfe_helper, formatter, base, locs, i, expected_result


def test_use_offset():
Expand Down
3 changes: 2 additions & 1 deletion 3 lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,8 @@ def __call__(self, x, pos=None):
elif abs(fx) < 1:
s = '%1.0g' % fx
else:
s = self.pprint_val(fx, d)
fd = math.log(abs(d)) / math.log(b)
s = self.pprint_val(fx, fd)
if sign == -1:
s = '-%s' % s

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.