8000 Axis tickmarks of 1e20 and higher fail · Issue #2652 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Axis tickmarks of 1e20 and higher fail #2652
Closed
@Anaphory

Description

@Anaphory

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.

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

      0