Skip to content

Commit 9d8d3ab

Browse files
committed
Response to review comments
1 parent 37b7993 commit 9d8d3ab

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -582,23 +582,32 @@ def test_percentformatter(self, xmax, decimals, symbol,
582582

583583

584584
class TestEngFormatter(object):
585-
def test_formatting(self):
585+
unit_data = ['', u's']
586+
587+
input_data = [0.1, 1, 999.9, 1001]
588+
589+
expected_data = {
590+
'': {
591+
0.1: u'100 m',
592+
1: u'1',
593+
999.99: u'999.9',
594+
1001: u'1.001 k',
595+
}
596+
u's': {
597+
0.1: u'100 ms',
598+
1: u'1 s',
599+
999.99: u'999.9 s',
600+
1001: u'1.001 ks',
601+
}
602+
}
603+
604+
@pytest.mark.parametrize('unit', unit_data)
605+
@pytest.mark.parametrize('input', input_data)
606+
def test_formatting(self, unit, input):
586607
"""
587-
Create two instances of EngFormatter with default parameters, with and
588-
without a unit string ('s' for seconds). Test the formatting in some
589-
cases, especially the case when no SI prefix is present, for values in
590-
[1, 1000).
591-
592-
Should not raise exceptions.
608+
Test the formatting of EngFormatter with some inputs, against
609+
instances with and without units. Cases focus on when no SI
610+
prefix is present, for values in [1, 1000).
593611
"""
594-
unitless = mticker.EngFormatter()
595-
assert unitless(0.1) == u'100 m'
596-
assert unitless(1) == u'1'
597-
assert unitless(999.9) == u'999.9'
598-
assert unitless(1001) == u'1.001 k'
599-
600-
with_unit = mticker.EngFormatter(unit=u's')
601-
assert with_unit(0.1) == u'100 ms'
602-
assert with_unit(1) == u'1 s'
603-
assert with_unit(999.9) == u'999.9 s'
604-
assert with_unit(1001) == u'1.001 ks'
612+
fmt = mticker.EngFormatter(unit)
613+
assert fmt(input) == self.expected_data[unit][input]

lib/matplotlib/ticker.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,20 @@
88
minor tick locating and formatting. Generic tick locators and
99
formatters are provided, as well as domain specific custom ones.
1010
11-
1211
Default Formatter
1312
-----------------
1413
1514
The default formatter identifies when the x-data being
1615
plotted is a small range on top of a large off set. To
1716
reduce the chances that the ticklabels overlap the ticks
18-
are labeled as deltas from a fixed offset. For example::
17+
are labeled as deltas from a fixed offset. For example::
1918
2019
ax.plot(np.arange(2000, 2010), range(10))
2120
2221
will have tick of 0-9 with an offset of +2e3. If this
2322
is not desired turn off the use of the offset on the default
2423
formatter::
2524
26-
2725
ax.get_xaxis().get_major_formatter().set_useOffset(False)
2826
2927
set the rcParam ``axes.formatter.useoffset=False`` to turn it off

0 commit comments

Comments
 (0)