Skip to content

2.1 change - Axis Limit Error  #9361

Closed
@2sn

Description

@2sn

Bug report

The new feature of raising exceptions for invalid limits and related changes seem to break code

Some new features in dealing with limits seem to break plotting, when using very small values (or NaN). I was not able to track down what is all broken, may be one than just one isolated change ... this worked smoothly in 2.0.2

import numpy as np
from matplotlib.pyplot import *
x = np.arange(-1000,10,1)
y = 10.**x
plot(x,y)
yscale('log')
ylim(1e-10, 1e10)
show()

if you now zoom out in "pan" mode eventually you run into error messages of the kind

ValueError: Axis limits cannot be NaN or Inf
Traceback (most recent call last):
  File "/home/alex/Python/lib/python3.6/site-packages/matplotlib/cbook/__init__.py", line 389, in process
    proxy(*args, **kwargs)
  File "/home/alex/Python/lib/python3.6/site-packages/matplotlib/cbook/__init__.py", line 227, in __call__
    return mtd(*args, **kwargs)
  File "/home/alex/Python/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 3056, in drag_pan
    a.drag_pan(self._button_pressed, event.key, event.x, event.y)
  File "/home/alex/Python/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 3837, in drag_pan
    self.set_ylim(*result.intervaly)
  File "/home/alex/Python/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 3226, in set_ylim
    top = self._validate_converted_limits(top, self.convert_yunits)
  File "/home/alex/Python/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2836, in _validate_converted_limits
    raise ValueError("Axis limits cannot be NaN or Inf")
ValueError: Axis limits cannot be NaN or Inf

and it all get very slow, I see the hour glass cursor for a line with 1000 points.

If you have a more complex plot with anything after this error these parts may be missing. Plot limits for axis get mutilated as well. I have also seen cases where home button no longer gets you back to the original limits ... For example, try to bus down really, really far (below 1e-300). After doing that, press home. For my test case, this showed me limits somewhere from 1e-50 to 1e+38. (in mpl 2.0.2 this does not happen)

Expected outcome

In Maplotlib 2.0.2, no error occurs, all runs smoothly. Values below threshold are truncated. Many of the plots I had are completely mutilated in this new version, I do not even know where I can start to look for a fix, as the errors do not point to any part of my code, nor is there an error raised in interactive mode where I could debug it. So it is not clear to me how I can help to find the problem in Matplotlib, or adjust my code from a 2.0.2-compatible version to one that works with 2.1.0.

(In 2.0.2 I only see a message as below.)

/home/alex/Python/lib/python3.6/site-packages/matplotlib/ticker.py:1076: RuntimeWarning: divide by zero encountered in double_scalars
  coeff = np.round(x / b ** exponent)

proposed fix

please revert to previous way of handling limits etc.

I assume this is related to

Invalid (Non-finite) Axis Limit Error
When using set_xlim() and set_ylim(), passing non-finite values now results in a ValueError. The previous behavior resulted in the limits being erroneously reset to (-0.001, 0.001).

from
http://matplotlib.org/api/api_changes.html#api-changes-in-2-1-0
specifically
http://matplotlib.org/api/api_changes.html#invalid-non-finite-axis-limit-error

Matplotlib version

  • Operating system: Fedora 26, 64bit
  • Matplotlib version: 2.1
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg
  • Python version: 3.6.3
  • Jupyter version (if applicable): N/A
  • Other libraries: numpy 1.13.3

pip3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions