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

Axis tickmarks of 1e20 and higher fail #2652

Closed
Anaphory opened this issue Dec 5, 2013 · 2 comments
Closed

Axis tickmarks of 1e20 and higher fail #2652

Anaphory opened this issue Dec 5, 2013 · 2 comments
Milestone

Comments

@Anaphory
Copy link

Anaphory commented Dec 5, 2013

Symptoms

Axis tickmarks with values of 1e20 or higher break a rendering process.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/home/gereon/sideprojects/selectionforagainst/generate_graphs.py", line 138, in <module>
    pl.savefig(os.path.join(folder, "xcor{:s}.png".format(run_id)))
  File "/usr/local/lib/python3.3/site-packages/matplotlib/pyplot.py", line 472, in savefig
    return fig.savefig(*args, **kwargs)
  File "/usr/local/lib/python3.3/site-packages/matplotlib/figure.py", line 1364, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/local/lib/python3.3/site-packages/matplotlib/backend_bases.py", line 2093, in print_figure
    **kwargs)
  File "/usr/local/lib/python3.3/site-packages/matplotlib/backends/backend_agg.py", line 491, in print_png
    FigureCanvasAgg.draw(self)
  File "/usr/local/lib/python3.3/site-packages/matplotlib/backends/backend_agg.py", line 439, in draw
    self.figure.draw(self.renderer)
  File "/usr/local/lib/python3.3/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python3.3/site-packages/matplotlib/figure.py", line 1000, in draw
    func(*args)
  File "/usr/local/lib/python3.3/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python3.3/site-packages/matplotlib/axes.py", line 2088, in draw
    a.draw(renderer)
  File "/usr/local/lib/python3.3/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python3.3/site-packages/matplotlib/axis.py", line 1049, in draw
    ticks_to_draw = self._update_ticks(renderer)
  File "/usr/local/lib/python3.3/site-packages/matplotlib/axis.py", line 936, in _update_ticks
    tick_tups = [t for t in self.iter_ticks()]
  File "/usr/local/lib/python3.3/site-packages/matplotlib/axis.py", line 936, in <listcomp>
    tick_tups = [t for t in self.iter_ticks()]
  File "/usr/local/lib/python3.3/site-packages/matplotlib/axis.py", line 882, in iter_ticks
    self.major.formatter.set_locs(majorLocs)
  File "/usr/local/lib/python3.3/site-packages/matplotlib/ticker.py", line 483, in set_locs
    self._set_format(vmin, vmax)
  File "/usr/local/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/local/lib/python3.3/site-packages/numpy/core/fromnumeric.py", line 2402, in round_
    return round(decimals, out)
AttributeError: 'float' object has no attribute 'rint'

Diagnosis

This happens due to line 539 in the definition of _set_format (in matplotlib/ticker.py):

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

For self.orderOfMagnitude>=20, 10**self.orderOfMagnitude cannot be cast into numpy.uint64, so the generated array is of dtype object, and this leads to the whole of locs acquiring that dtype. The resulting objects matplotlib tries to round in the later steps are therefore not numpy.float64s, but python floats, which do not have an rint method.

Fix suggestion

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

If I were more familiar with the intestines of matplotlib, this might just be a pull request, but from my current perspective I cannot decide how much just making the 10 a float, and thereby making the full thing become a numpy.array of numpy.float64s, might break other things.

@tacaswell
Copy link
Member

Thanks for the nice report.

I would suggest making a PR with that change. It is the best way to get feed back on the change and the test suite (which you can/should run locally) will tell us if this breaks anything.

@tacaswell
Copy link
Member

It looks like this was already fixed in #1991 which preceded v1.3.0. @Anaphory what version of mpl were you using?

I am closing this, please re-open if this is still a problem for you.

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

2 participants