Skip to content

Patch for issue #6009 #6014

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 7 commits into from
Jun 6, 2016
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,26 @@ def test_percentformatter():
yield (_percent_format_helper,) + case


def test_EngFormatter_formatting():
"""
Create two instances of EngFormatter with default parameters, with and
without a unit string ('s' for seconds). Test the formatting in some cases,
especially the case when no SI prefix is present, for values in [1, 1000).

Should not raise exceptions.
"""
unitless = mticker.EngFormatter()
nose.tools.assert_equal(unitless(0.1), u'100 m')
nose.tools.assert_equal(unitless(1), u'1')
nose.tools.assert_equal(unitless(999.9), u'999.9')
nose.tools.assert_equal(unitless(1001), u'1.001 k')

with_unit = mticker.EngFormatter(unit=u's')
nose.tools.assert_equal(with_unit(0.1), u'100 ms')
nose.tools.assert_equal(with_unit(1), u'1 s')
nose.tools.assert_equal(with_unit(999.9), u'999.9 s')
nose.tools.assert_equal(with_unit(1001), u'1.001 ks')

if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
8 changes: 6 additions & 2 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ class EngFormatter(Formatter):
suitable for use with single-letter representations of powers of
1000. For example, 'Hz' or 'm'.

`places` is the percision with which to display the number,
`places` is the precision with which to display the number,
specified in digits after the decimal point (there will be between
one and three digits before the decimal point).
"""
Expand Down Expand Up @@ -1113,7 +1113,11 @@ def format_eng(self, num):

formatted = format_str % (mant, prefix)

return formatted.strip()
formatted = formatted.strip()
if (self.unit != "") and (prefix == self.ENG_PREFIXES[0]):
formatted = formatted + " "

return formatted


class PercentFormatter(Formatter):
Expand Down