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

tricky bug in ticker due to special behaviour of numpy #6301

Copy link
Copy link
Closed
@2sn

Description

@2sn
Issue body actions
  • Matplotlib version, Python version and Platform (Windows, OSX, Linux ...)
    1.5.1 / 3.5.1 / Fedora 23 64 bit
  • How did you install Matplotlib and Python (pip, anaconda, from source ...)
    pip3 on private install of Python 3.5.1
  • If possible please supply a Short, Self Contained, Correct, Example
    that demonstrates the issue i.e a small piece of code which reproduces the issue
    and can be run with out any other (or as few as possible) external dependencies.
> ipython3 -pylab
Python 3.5.1 (default, Apr 14 2016, 22:46:05) 
Type "copyright", "credits" or "license" for more information.

IPython 4.1.2 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: plot((1+np.array([0, 1.e-12]))*1.e27)
Out[1]: [<matplotlib.lines.Line2D at 0x7f985b6a1c88>]

In [2]: Exception in Tkinter callback
Traceback (most recent call last):
  File "/home/alex/Python/lib/python3.5/tkinter/__init__.py", line 1549, in __call__
    return self.func(*args)
  File "/home/alex/Python/lib/python3.5/tkinter/__init__.py", line 596, in callit
    func(*args)
  File "/home/alex/Python/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py", line 373, in idle_draw
    self.draw()
  File "/home/alex/Python/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py", line 354, in draw
    FigureCanvasAgg.draw(self)
  File "/home/alex/Python/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py", line 474, in draw
    self.figure.draw(self.renderer)
  File "/home/alex/Python/lib/python3.5/site-packages/matplotlib/artist.py", line 61, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/alex/Python/lib/python3.5/site-packages/matplotlib/figure.py", line 1159, in draw
    func(*args)
  File "/home/alex/Python/lib/python3.5/site-packages/matplotlib/artist.py", line 61, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/alex/Python/lib/python3.5/site-packages/matplotlib/axes/_base.py", line 2324, in draw
    a.draw(renderer)
  File "/home/alex/Python/lib/python3.5/site-packages/matplotlib/artist.py", line 61, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/alex/Python/lib/python3.5/site-packages/matplotlib/axis.py", line 1106, in draw
    ticks_to_draw = self._update_ticks(renderer)
  File "/home/alex/Python/lib/python3.5/site-packages/matplotlib/axis.py", line 949, in _update_ticks
    tick_tups = [t for t in self.iter_ticks()]
  File "/home/alex/Python/lib/python3.5/site-packages/matplotlib/axis.py", line 949, in <listcomp>
    tick_tups = [t for t in self.iter_ticks()]
  File "/home/alex/Python/lib/python3.5/site-packages/matplotlib/axis.py", line 894, in iter_ticks
    self.major.formatter.set_locs(majorLocs)
  File "/home/alex/Python/lib/python3.5/site-packages/matplotlib/ticker.py", line 537, in set_locs
    self._set_format(vmin, vmax)
  File "/home/alex/Python/lib/python3.5/site-packages/matplotlib/ticker.py", line 610, in _set_format
    if np.abs(locs - np.round(locs, decimals=sigfigs)).max() < thresh:
  File "/home/alex/Python/lib/python3.5/site-packages/numpy/core/fromnumeric.py", line 2793, in round_
    return round(decimals, out)
AttributeError: 'float' object has no attribute 'rint'
  • If this is an image generation bug attach a screenshot demonstrating the issue.

N/A

  • If this is a regression (Used to work in an earlier version of Matplotlib), please
    note where it used to work.

Did not work in recent past. (I just modified numpy to make matplotlib work, but the bug, really, is in matplotlib.)

The bug is in ticker.py, line 593

        locs = (np.asarray(_locs) - self.offset) / 10. ** self.orderOfMagnitude

here self.offset is a large python integer in this case rather than a float. The resulting object of the first subtraction is a numpy.ndarray of dtype numpy.object with the objects being python floats (rather than a numpy.ndarray of a numeric dtype like numpy.float64

In [1]: np.asarray([1.,2.,3.]) + 1000000000000000000000000000
Out[1]: array([1e+27, 1e+27, 1e+27], dtype=object)

With this kind of object the latter call to numpy.round fails.

The easiest fix would be change the above line to

        locs = (np.asarray(_locs) - np.float(self.offset)) * 0.1 ** self.orderOfMagnitude

alternatively, the part in ticker.py where self.offset is computer could return floats, but there is many places where this is set to make it a float in general, and this may have further side effects.

Could you please fix this?

-Alexander

PS - As a side note, for the sake of execution speed one should replace " / 10. ** x" by " * 0.1 ** x".

PPS - I also submitted a bug report to numpy in the hope the np.round can be changed to accept numpy.ndarrays of dtype numpy.object with numerical object types. numpy/numpy#7547

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

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