8000 FIX: formatting in LogFormatterExponent by tacaswell · Pull Request #5594 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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
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
Prev Previous commit
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)]))
  • Loading branch information
tacaswell committed Dec 1, 2015
commit f9c8aa18f80eb2a7c6c9fbb189e72fa8d464f9aa
146 changes: 146 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,152 @@ def get_view_interval(self):
yield _logfe_helper, formatter, base, locs, i, expected_result


def _pprint_helper(value, domain, expected):
fmt = mticker.LogFormatter()
label = fmt.pprint_val(value, domain)
nose.tools.assert_equal(label, expected)


def test_logformatter_pprint():
test_cases = (
(3.141592654e-05, 0.001, '3.142e-5'),
(0.0003141592654, 0.001, '3.142e-4'),
(0.003141592654, 0.001, '3.142e-3'),
(0.03141592654, 0.001, '3.142e-2'),
(0.3141592654, 0.001, '3.142e-1'),
(3.141592654, 0.001, '3.142'),
(31.41592654, 0.001, '3.142e1'),
(314.1592654, 0.001, '3.142e2'),
(3141.592654, 0.001, '3.142e3'),
(31415.92654, 0.001, '3.142e4'),
(314159.2654, 0.001, '3.142e5'),
(1e-05, 0.001, '1e-5'),
(0.0001, 0.001, '1e-4'),
(0.001, 0.001, '1e-3'),
(0.01, 0.001, '1e-2'),
(0.1, 0.001, '1e-1'),
(1, 0.001, '1'),
(10, 0.001, '10'),
(100, 0.001, '100'),
(1000, 0.001, '1000'),
(10000, 0.001, '1e4'),
(100000, 0.001, '1e5'),
(3.141592654e-05, 0.015, '0'),
(0.0003141592654, 0.015, '0'),
(0.003141592654, 0.015, '0.003'),
(0.03141592654, 0.015, '0.031'),
(0.3141592654, 0.015, '0.314'),
(3.141592654, 0.015, '3.142'),
(31.41592654, 0.015, '31.416'),
(314.1592654, 0.015, '314.159'),
(3141.592654, 0.015, '3141.593'),
(31415.92654, 0.015, '31415.927'),
(314159.2654, 0.015, '314159.265'),
(1e-05, 0.015, '0'),
(0.0001, 0.015, '0'),
(0.001, 0.015, '0.001'),
(0.01, 0.015, '0.01'),
(0.1, 0.015, '0.1'),
(1, 0.015, '1'),
(10, 0.015, '10'),
(100, 0.015, '100'),
(1000, 0.015, '1000'),
(10000, 0.015, '10000'),
(100000, 0.015, '100000'),
(3.141592654e-05, 0.5, '0'),
(0.0003141592654, 0.5, '0'),
(0.003141592654, 0.5, '0.003'),
(0.03141592654, 0.5, '0.031'),
(0.3141592654, 0.5, '0.314'),
(3.141592654, 0.5, '3.142'),
(31.41592654, 0.5, '31.416'),
(314.1592654, 0.5, '314.159'),
(3141.592654, 0.5, '3141.593'),
(31415.92654, 0.5, '31415.927'),
(314159.2654, 0.5, '314159.265'),
(1e-05, 0.5, '0'),
(0.0001, 0.5, '0'),
(0.001, 0.5, '0.001'),
(0.01, 0.5, '0.01'),
(0.1, 0.5, '0.1'),
(1, 0.5, '1'),
(10, 0.5, '10'),
(100, 0.5, '100'),
(1000, 0.5, '1000'),
(10000, 0.5, '10000'),
(100000, 0.5, '100000'),
(3.141592654e-05, 5, '0'),
(0.0003141592654, 5, '0'),
(0.003141592654, 5, '0'),
(0.03141592654, 5, '0.03'),
(0.3141592654, 5, '0.31'),
(3.141592654, 5, '3.14'),
(31.41592654, 5, '31.42'),
(314.1592654, 5, '314.16'),
(3141.592654, 5, '3141.59'),
(31415.92654, 5, '31415.93'),
(314159.2654, 5, '314159.27'),
(1e-05, 5, '0'),
(0.0001, 5, '0'),
(0.001, 5, '0'),
(0.01, 5, '0.01'),
(0.1, 5, '0.1'),
(1, 5, '1'),
(10, 5, '10'),
(100, 5, '100'),
(1000, 5, '1000'),
(10000, 5, '10000'),
(100000, 5, '100000'),
(3.141592654e-05, 100, '0'),
(0.0003141592654, 100, '0'),
(0.003141592654, 100, '0'),
(0.03141592654, 100, '0'),
(0.3141592654, 100, '0.3'),
(3.141592654, 100, '3.1'),
(31.41592654, 100, '31.4'),
(314.1592654, 100, '314.2'),
(3141.592654, 100, '3141.6'),
(31415.92654, 100, '31415.9'),
(314159.2654, 100, '314159.3'),
(1e-05, 100, '0'),
(0.0001, 100, '0'),
(0.001, 100, '0'),
(0.01, 100, '0'),
(0.1, 100, '0.1'),
(1, 100, '1'),
(10, 100, '10'),
(100, 100, '100'),
(1000, 100, '1000'),
(10000, 100, '10000'),
(100000, 100, '100000'),
(3.141592654e-05, 1000000.0, '3.1e-5'),
(0.0003141592654, 1000000.0, '3.1e-4'),
(0.003141592654, 1000000.0, '3.1e-3'),
(0.03141592654, 1000000.0, '3.1e-2'),
(0.3141592654, 1000000.0, '3.1e-1'),
(3.141592654, 1000000.0, '3.1'),
(31.41592654, 1000000.0, '3.1e1'),
(314.1592654, 1000000.0, '3.1e2'),
(3141.592654, 1000000.0, '3.1e3'),
(31415.92654, 1000000.0, '3.1e4'),
(314159.2654, 1000000.0, '3.1e5'),
(1e-05, 1000000.0, '1e-5'),
(0.0001, 1000000.0, '1e-4'),
(0.001, 1000000.0, '1e-3'),
(0.01, 1000000.0, '1e-2'),
(0.1, 1000000.0, '1e-1'),
(1, 1000000.0, '1'),
(10, 1000000.0, '10'),
(100, 1000000.0, '100'),
(1000, 1000000.0, '1000'),
(10000, 1000000.0, '1e4'),
(100000, 1000000.0, '1e5')
)

for value, domain, expected in test_cases:
yield _pprint_helper, value, domain, expected


def test_use_offset():
for use_offset in [True, False]:
with matplotlib.rc_context({'axes.formatter.useoffset': use_offset}):
Expand Down
0