Skip to content
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

AttributeError with big float Value(s) #1828

Closed
ElricleNecro opened this issue Mar 15, 2013 · 10 comments
Closed

AttributeError with big float Value(s) #1828

ElricleNecro opened this issue Mar 15, 2013 · 10 comments

Comments

@ElricleNecro
Copy link

When I use some important value in my plot, i get the error :

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.3/tkinter/__init__.py", line 1442, in __call__
    return self.func(*args)
  File "/usr/lib/python3.3/site-packages/matplotlib/backends/backend_tkagg.py", line 276, in resize
    self.show()
  File "/usr/lib/python3.3/site-packages/matplotlib/backends/backend_tkagg.py", line 348, in draw
    FigureCanvasAgg.draw(self)
  File "/usr/lib/python3.3/site-packages/matplotlib/backends/backend_agg.py", line 439, in draw
    self.figure.draw(self.renderer)
  File "/usr/lib/python3.3/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3.3/site-packages/matplotlib/figure.py", line 1000, in draw
    func(*args)
  File "/usr/lib/python3.3/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3.3/site-packages/matplotlib/axes.py", line 2088, in draw
    a.draw(renderer)
  File "/usr/lib/python3.3/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3.3/site-packages/matplotlib/axis.py", line 1049, in draw
    ticks_to_draw = self._update_ticks(renderer)
  File "/usr/lib/python3.3/site-packages/matplotlib/axis.py", line 936, in _update_ticks
    tick_tups = [t for t in self.iter_ticks()]
  File "/usr/lib/python3.3/site-packages/matplotlib/axis.py", line 936, in <listcomp>
    tick_tups = [t for t in self.iter_ticks()]
  File "/usr/lib/python3.3/site-packages/matplotlib/axis.py", line 882, in iter_ticks
    self.major.formatter.set_locs(majorLocs)
  File "/usr/lib/python3.3/site-packages/matplotlib/ticker.py", line 483, in set_locs
    self._set_format(vmin, vmax)
  File "/usr/lib/python3.3/site-packages/matplotlib/ticker.py", line 550, in _set_format
    if np.abs(locs - np.round(locs, decimals=sigfigs)).max() < thresh:
  File "/usr/lib/python3.3/site-packages/numpy/core/fromnumeric.py", line 2402, in round_
    return round(decimals, out)
AttributeError: 'float' object has no attribute 'rint'

Here is a little piece of code which reproduces the error :

from matplotlib import pyplot as plt
import numpy as np

x = np.arange(0, 3, 1)
y = x*1e35

print(y)

plt.ioff()
plt.plot(x, y)
plt.show()
@pelson
Copy link
Member

pelson commented Mar 18, 2013

I can't reproduce this on my RHELinux 64bit machine with python2.7, mpl 1.3.x, tkagg backend, and numpy 1.6. Can you provide some details about your setup? Have you got python2.7 to give this a go on?

Cheers,

@ElricleNecro
Copy link
Author

I am using mpl 1.3.x (tested with 1.2.0 too) with tkagg backend, numpy 1.7 (but the string matplotlib.version__numpy indicate 1.4, numpy.version gives me 1.7), python 3.3, ipython 0.13.1
For the OS: archlinux 64bit.

cheers,

EDIT: tested on python2.7 with mpl 1.3.X, tkagg backend and numpy 1.6.1, and it's working. This bug seems to be specific to python 3.3.

@WeatherGod
Copy link
Member

On Mon, Mar 18, 2013 at 6:14 AM, GuillaumePlum notifications@github.comwrote:

I am using mpl 1.3.x (tested with 1.2.0 too) with tkagg backend, numpy 1.7
(but the string matplotlib.version__numpy indicate 1.4,
numpy.version gives me 1.7), python 3.3, ipython 0.13.1
For the OS: archlinux 64bit.

Just to note, matplotlib.version__numpy merely indicates the lowest
version of numpy that is supported by matplotlib.

@dmcdougall
Copy link
Member

I can't reproduce this on OS X 10.8 64 bit with python 2.7, mpl 1.2.x, gtkagg backend and numpy 1.6.2.

@ElricleNecro
Copy link
Author

Like I've said above, this bug seems to be specific to python 3.

I've tested it on different configuration using python3.2 and python3.3 with mpl 1.2.X and 1.3.x (git version), using different Linux distribution (ArchLinux, Debian, Ubuntu), in case of I've broke something.

But when using python2.7, it's all working... It's a little weird. Adding print to every variable used in those functions (set_format and round) seems useless, they're printing the same thing.

(Sorry for the english!)

@tomcraw00
Copy link

I have the same issue:
Python 3.3, matplotlib 1.3.x (latest trunk), numpy 1.7
OS X 10.8 mountain lion, macbook pro retina

I cannot plot a number > 8.9999E+19

/usr/local/lib/python3.3/site-packages/numpy/core/fromnumeric.py in round_(a=array([0.0, 0.2, 0.4, 0.6, 0.8, 1.0], dtype=object), decimals=3, out=None)
2400 except AttributeError:
2401 return _wrapit(a, 'round', decimals, out)
-> 2402 return round(decimals, out)
round = <built-in method round of numpy.ndarray object at 0x7fce4cae9990>
decimals = 3
out = None
2403
2404

@mdboom
Copy link
Member

mdboom commented Apr 25, 2013

Strange -- I can't reproduce on Python 3.3, Numpy 1.7.1, matplotlib 1.2.x branch on Linux (Fedora 18). Any chance you can run this in pdb and print the value of "decimals" in the innermost stack frame?

@ElricleNecro
Copy link
Author

Just before the exception in the round_ function, i have:

a = [0.0 0.5 1.0 1.5 2.0]
decimals = 3
out = None

Using the code give in the first post.

mdboom added a commit to mdboom/matplotlib that referenced this issue May 10, 2013
@2sn
Copy link

2sn commented May 10, 2013

It's not an overflow, but current numpy 1.7.1 does not like to convert huge integers that python 3.3 produces into np data types. Instead, it saves them as an object (dtype=object, the object type is builtins.int). Not sure this is a feature or a bug (of numpy). Probably a feature - someone must have thought that would be clever. Instead of producing an overflow.

In [1]: np.array([10**25])
Out[1]: array([10000000000000000000000000], dtype=object)

In [2]: x = np.array([10**25])
In [3]: x[0].dtype

AttributeError Traceback (most recent call last)
in ()
----> 1 x[0].dtype

AttributeError: 'int' object has no attribute 'dtype'

In [4]: type(x[0])
Out[4]: builtins.int

In [5]: np.array([10**5])
Out[5]: array([100000])

In [7]: x = np.array([10**5])

In [8]: type(x[0])
Out[8]: numpy.int64

@mdboom
Copy link
Member

mdboom commented May 10, 2013

Fixed by #1991.

@mdboom mdboom closed this as completed May 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants