Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ticker.py: always use np.round? #27609

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
29 changes: 29 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@
(3, 1e2, '$\\mathdefault{100}$'),
(3, 1e-3, '$\\mathdefault{10^{-3}}$'),
(3, 1e3, '$\\mathdefault{10^{3}}$'),
(2, np.inf, ''),
]

@pytest.mark.parametrize('min_exponent, value, expected', test_data)
Expand Down Expand Up @@ -1259,6 +1260,13 @@
temp_lf.axis.set_view_interval(1, 10)
temp_lf(val)

@pytest.mark.parametrize('val', [1e+323, 2e+323, 10e+323, 11e+323])
def test_LogFormatter_call_big(self, val):
# test coeff computation in __call__
temp_lf = mticker.LogFormatter()
temp_lf.create_dummy_axis()
temp_lf(val)


class TestLogitFormatter:
@staticmethod
Expand Down Expand Up @@ -1835,6 +1843,27 @@
assert (np.diff(np.log10(ll.tick_values(6, 150))) == 1).all()


# https://github.com/matplotlib/matplotlib/pull/27609
# TODO: This test currently fails, as expected and it needs to be fixed...
# To do this completely correctly, we should figure out what are our limits
# for when do integers are interpreted eventually as infinities and why,
# and perhaps always work with np.float128 to increase accuracy as much as
# possible. Eitherway, we should document what is our limit and how it is
# related to the accuracy of np.float{64,128} and Python's native float
# which seems to be the same as np.float64 for this purpose...
def test_LogFormatter_almost_inf():
fig, ax = plt.subplots()
# TODO: Figure out why 1e400 won't fail, but will make the ax.plot describe
# 1e400 as inf (and hence not print it, and hence not fail).
ax.plot([1, 2], [1, 1e300])
ax.set_yscale("log")
fig.draw_without_rendering()
almost_inf = ax.get_lines()[0].get_ydata()[1]

Check warning on line 1861 in lib/matplotlib/tests/test_ticker.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/tests/test_ticker.py#L1861

Added line #L1861 was not covered by tests
# TODO/WIP: remove of course when the above TODOs are fixed. Perhaps assert
# something with ydata...
assert True == False

Check failure on line 1864 in lib/matplotlib/tests/test_ticker.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] reported by reviewdog 🐶 E712 comparison to True should be 'if cond is True:' or 'if cond:' Raw Output: ./lib/matplotlib/tests/test_ticker.py:1864:17: E712 comparison to True should be 'if cond is True:' or 'if cond:'

Check warning on line 1864 in lib/matplotlib/tests/test_ticker.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/tests/test_ticker.py#L1864

Added line #L1864 was not covered by tests


def test_NullFormatter():
formatter = mticker.NullFormatter()
assert formatter(1.0) == ''
Expand Down
4 changes: 4 additions & 0 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,8 @@ def __call__(self, x, pos=None):
return '0'

x = abs(x)
if not np.isfinite(x):
return ''
b = self._base
# only label the decades
fx = math.log(x) / math.log(b)
Expand Down Expand Up @@ -1081,6 +1083,8 @@ def __call__(self, x, pos=None):

sign_string = '-' if x < 0 else ''
x = abs(x)
if not np.isfinite(x):
return ''
b = self._base

# only label the decades
Expand Down
Loading