Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit59e0ab9

Browse files
committed
Merge pull request#6014 from afvincent/afvincent-patch-issue-6009
FIX: EngFormatter without but without prefixcloses#6009
1 parent1e35d8d commit59e0ab9

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

‎lib/matplotlib/tests/test_ticker.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,27 @@ def test_formatstrformatter():
413413
tmp_form=mticker.StrMethodFormatter('{x:05d}')
414414
nose.tools.assert_equal('00002',tmp_form(2))
415415

416+
417+
deftest_EngFormatter_formatting():
418+
"""
419+
Create two instances of EngFormatter with default parameters, with and
420+
without a unit string ('s' for seconds). Test the formatting in some cases,
421+
especially the case when no SI prefix is present, for values in [1, 1000).
422+
423+
Should not raise exceptions.
424+
"""
425+
unitless=mticker.EngFormatter()
426+
nose.tools.assert_equal(unitless(0.1),u'100 m')
427+
nose.tools.assert_equal(unitless(1),u'1')
428+
nose.tools.assert_equal(unitless(999.9),u'999.9')
429+
nose.tools.assert_equal(unitless(1001),u'1.001 k')
430+
431+
with_unit=mticker.EngFormatter(unit=u's')
432+
nose.tools.assert_equal(with_unit(0.1),u'100 ms')
433+
nose.tools.assert_equal(with_unit(1),u'1 s')
434+
nose.tools.assert_equal(with_unit(999.9),u'999.9 s')
435+
nose.tools.assert_equal(with_unit(1001),u'1.001 ks')
436+
416437
if__name__=='__main__':
417438
importnose
418439
nose.runmodule(argv=['-s','--with-doctest'],exit=False)

‎lib/matplotlib/ticker.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ class EngFormatter(Formatter):
10051005
suitable for use with single-letter representations of powers of
10061006
1000. For example, 'Hz' or 'm'.
10071007
1008-
`places` is thepercision with which to display the number,
1008+
`places` is theprecision with which to display the number,
10091009
specified in digits after the decimal point (there will be between
10101010
one and three digits before the decimal point).
10111011
"""
@@ -1087,7 +1087,11 @@ def format_eng(self, num):
10871087

10881088
formatted=format_str% (mant,prefix)
10891089

1090-
returnformatted.strip()
1090+
formatted=formatted.strip()
1091+
if (self.unit!="")and (prefix==self.ENG_PREFIXES[0]):
1092+
formatted=formatted+" "
1093+
1094+
returnformatted
10911095

10921096

10931097
classLocator(TickHelper):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp