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

Commit f9c8aa1

Browse filesBrowse files
committed
TST: shotgun testing of LogFormatter.pprint_val
Code used to generate the test data to establish bench mark. First print out is human-readable, second is for testing import itertools import matplotlib.ticker as mticker import numpy as np domains = sorted([1e-3, 1.5e-2, 1e6, 100, 5, .5]) float_values = sorted([np.pi * (10**i) for i in range(-5, 6)]) int_values = sorted([1 * (10 ** i) for i in range(-5, 6)]) fmt = mticker.LogFormatter() print() for d in domains: print('Domain ', d) for f in float_values: print(' {: >10.7f}: {: <10}'.format(f, fmt.pprint_val(f, d))) for f in int_values: print(' {: >10g}: {: <10}'.format(f, fmt.pprint_val(f, d))) print() print() print(',\n'.join([' ({v:.10g}, {d!r}, {res!r})'.format( v=f, d=d, res=fmt.pprint_val(f, d)) for d, f in itertools.product( domains, float_values + int_values)]))
1 parent 7566447 commit f9c8aa1
Copy full SHA for f9c8aa1

File tree

Expand file treeCollapse file tree

1 file changed

+146
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+146
-0
lines changed

‎lib/matplotlib/tests/test_ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_ticker.py
+146Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,152 @@ def get_view_interval(self):
204204
yield _logfe_helper, formatter, base, locs, i, expected_result
205205

206206

207+
def _pprint_helper(value, domain, expected):
208+
fmt = mticker.LogFormatter()
209+
label = fmt.pprint_val(value, domain)
210+
nose.tools.assert_equal(label, expected)
211+
212+
213+
def test_logformatter_pprint():
214+
test_cases = (
215+
(3.141592654e-05, 0.001, '3.142e-5'),
216+
(0.0003141592654, 0.001, '3.142e-4'),
217+
(0.003141592654, 0.001, '3.142e-3'),
218+
(0.03141592654, 0.001, '3.142e-2'),
219+
(0.3141592654, 0.001, '3.142e-1'),
220+
(3.141592654, 0.001, '3.142'),
221+
(31.41592654, 0.001, '3.142e1'),
222+
(314.1592654, 0.001, '3.142e2'),
223+
(3141.592654, 0.001, '3.142e3'),
224+
(31415.92654, 0.001, '3.142e4'),
225+
(314159.2654, 0.001, '3.142e5'),
226+
(1e-05, 0.001, '1e-5'),
227+
(0.0001, 0.001, '1e-4'),
228+
(0.001, 0.001, '1e-3'),
229+
(0.01, 0.001, '1e-2'),
230+
(0.1, 0.001, '1e-1'),
231+
(1, 0.001, '1'),
232+
(10, 0.001, '10'),
233+
(100, 0.001, '100'),
234+
(1000, 0.001, '1000'),
235+
(10000, 0.001, '1e4'),
236+
(100000, 0.001, '1e5'),
237+
(3.141592654e-05, 0.015, '0'),
238+
(0.0003141592654, 0.015, '0'),
239+
(0.003141592654, 0.015, '0.003'),
240+
(0.03141592654, 0.015, '0.031'),
241+
(0.3141592654, 0.015, '0.314'),
242+
(3.141592654, 0.015, '3.142'),
243+
(31.41592654, 0.015, '31.416'),
244+
(314.1592654, 0.015, '314.159'),
245+
(3141.592654, 0.015, '3141.593'),
246+
(31415.92654, 0.015, '31415.927'),
247+
(314159.2654, 0.015, '314159.265'),
248+
(1e-05, 0.015, '0'),
249+
(0.0001, 0.015, '0'),
250+
(0.001, 0.015, '0.001'),
251+
(0.01, 0.015, '0.01'),
252+
(0.1, 0.015, '0.1'),
253+
(1, 0.015, '1'),
254+
(10, 0.015, '10'),
255+
(100, 0.015, '100'),
256+
(1000, 0.015, '1000'),
257+
(10000, 0.015, '10000'),
258+
(100000, 0.015, '100000'),
259+
(3.141592654e-05, 0.5, '0'),
260+
(0.0003141592654, 0.5, '0'),
261+
(0.003141592654, 0.5, '0.003'),
262+
(0.03141592654, 0.5, '0.031'),
263+
(0.3141592654, 0.5, '0.314'),
264+
(3.141592654, 0.5, '3.142'),
265+
(31.41592654, 0.5, '31.416'),
266+
(314.1592654, 0.5, '314.159'),
267+
(3141.592654, 0.5, '3141.593'),
268+
(31415.92654, 0.5, '31415.927'),
269+
(314159.2654, 0.5, '314159.265'),
270+
(1e-05, 0.5, '0'),
271+
(0.0001, 0.5, '0'),
272+
(0.001, 0.5, '0.001'),
273+
(0.01, 0.5, '0.01'),
274+
(0.1, 0.5, '0.1'),
275+
(1, 0.5, '1'),
276+
(10, 0.5, '10'),
277+
(100, 0.5, '100'),
278+
(1000, 0.5, '1000'),
279+
(10000, 0.5, '10000'),
280+
(100000, 0.5, '100000'),
281+
(3.141592654e-05, 5, '0'),
282+
(0.0003141592654, 5, '0'),
283+
(0.003141592654, 5, '0'),
284+
(0.03141592654, 5, '0.03'),
285+
(0.3141592654, 5, '0.31'),
286+
(3.141592654, 5, '3.14'),
287+
(31.41592654, 5, '31.42'),
288+
(314.1592654, 5, '314.16'),
289+
(3141.592654, 5, '3141.59'),
290+
(31415.92654, 5, '31415.93'),
291+
(314159.2654, 5, '314159.27'),
292+
(1e-05, 5, '0'),
293+
(0.0001, 5, '0'),
294+
(0.001, 5, '0'),
295+
(0.01, 5, '0.01'),
296+
(0.1, 5, '0.1'),
297+
(1, 5, '1'),
298+
(10, 5, '10'),
299+
(100, 5, '100'),
300+
(1000, 5, '1000'),
301+
(10000, 5, '10000'),
302+
(100000, 5, '100000'),
303+
(3.141592654e-05, 100, '0'),
304+
(0.0003141592654, 100, '0'),
305+
(0.003141592654, 100, '0'),
306+
(0.03141592654, 100, '0'),
307+
(0.3141592654, 100, '0.3'),
308+
(3.141592654, 100, '3.1'),
309+
(31.41592654, 100, '31.4'),
310+
(314.1592654, 100, '314.2'),
311+
(3141.592654, 100, '3141.6'),
312+
(31415.92654, 100, '31415.9'),
313+
(314159.2654, 100, '314159.3'),
314+
(1e-05, 100, '0'),
315+
(0.0001, 100, '0'),
316+
(0.001, 100, '0'),
317+
(0.01, 100, '0'),
318+
(0.1, 100, '0.1'),
319+
(1, 100, '1'),
320+
(10, 100, '10'),
321+
(100, 100, '100'),
322+
(1000, 100, '1000'),
323+
(10000, 100, '10000'),
324+
(100000, 100, '100000'),
325+
(3.141592654e-05, 1000000.0, '3.1e-5'),
326+
(0.0003141592654, 1000000.0, '3.1e-4'),
327+
(0.003141592654, 1000000.0, '3.1e-3'),
328+
(0.03141592654, 1000000.0, '3.1e-2'),
329+
(0.3141592654, 1000000.0, '3.1e-1'),
330+
(3.141592654, 1000000.0, '3.1'),
331+
(31.41592654, 1000000.0, '3.1e1'),
332+
(314.1592654, 1000000.0, '3.1e2'),
333+
(3141.592654, 1000000.0, '3.1e3'),
334+
(31415.92654, 1000000.0, '3.1e4'),
335+
(314159.2654, 1000000.0, '3.1e5'),
336+
(1e-05, 1000000.0, '1e-5'),
337+
(0.0001, 1000000.0, '1e-4'),
338+
(0.001, 1000000.0, '1e-3'),
339+
(0.01, 1000000.0, '1e-2'),
340+
(0.1, 1000000.0, '1e-1'),
341+
(1, 1000000.0, '1'),
342+
(10, 1000000.0, '10'),
343+
(100, 1000000.0, '100'),
344+
(1000, 1000000.0, '1000'),
345+
(10000, 1000000.0, '1e4'),
346+
(100000, 1000000.0, '1e5')
347+
)
348+
349+
for value, domain, expected in test_cases:
350+
yield _pprint_helper, value, domain, expected
351+
352+
207353
def test_use_offset():
208354
for use_offset in [True, False]:
209355
with matplotlib.rc_context({'axes.formatter.useoffset': use_offset}):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.