You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
calling annotate with nan values for the position still gives error after 3.0.2 #13276
There was a previous issue #12648 which noted a regression in Matplotlib which meant calling annotate with a nan position caused an error when using the command plt.tight_layout(). This issue was then closed by #12651, however with Matplotlib 3.0.2 I still am recieving an error with the following code, which I think should be functionally the same:
importmatplotlib.pyplotaspltfig, ax=plt.subplots()
ax.annotate("", xy=(0, float('nan')))
# If axis is set on then a ValueError is thrown when calculating ticks# If axis is set off then a RuntimeError: libpng signaled error is thrownax.set_axis_off()
fig.savefig("bar.png", bbox_inches='tight')
Actual outcome
libpng warning: Image width is zero in IHDR
libpng warning: Image height is zero in IHDR
libpng error: Invalid IHDR data
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/michael/conda/envs/nnpdf/lib/python3.7/site-packages/matplotlib/figure.py", line 2094, in savefig
self.canvas.print_figure(fname, **kwargs)
File "/Users/michael/conda/envs/nnpdf/lib/python3.7/site-packages/matplotlib/backend_bases.py", line 2075, in print_figure
**kwargs)
File "/Users/michael/conda/envs/nnpdf/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py", line 523, in print_png
self.figure.dpi, metadata=metadata)
RuntimeError: libpng signaled error
Expected outcome
I think this minimal example should just return an empty figure and ignore the annotation with NaN position. Maybe I'm mistaken but I would have thought it should be the same output as
We special case no artist, and handle the case of just one artist with an invalid bounding box, but fail on the case with only artists with invalid bounding boxes.
I'll have a PR in shortly.
Thanks for the extremely clear example (it is going to made into a test!).
Thanks for the reply! Perhaps the ValueError is dependent on numpy version, otherwise I'm not sure. I'm getting it with numpy 1.15.4 py37hacdab7b_0
and numpy-base 1.15.4 py37h6575580_0
Full traceback in case it's more instructive:
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> ax.annotate("", xy=(0,float('nan')))
Text(0, nan, '')
>>> fig.savefig("foo.png", bbox_inches='tight')
/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/numpy/core/fromnumeric.py:83: RuntimeWarning: invalid value encountered in reduce
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/figure.py", line 2094, in savefig
self.canvas.print_figure(fname, **kwargs)
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/backend_bases.py", line 2075, in print_figure
**kwargs)
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py", line 510, in print_png
FigureCanvasAgg.draw(self)
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py", line 402, in draw
self.figure.draw(self.renderer)
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/figure.py", line 1649, in draw
renderer, self, artists, self.suppressComposite)
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/image.py", line 138, in _draw_list_compositing_images
a.draw(renderer)
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 2628, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/image.py", line 138, in _draw_list_compositing_images
a.draw(renderer)
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/axis.py", line 1185, in draw
ticks_to_draw = self._update_ticks(renderer)
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/axis.py", line 1023, in _update_ticks
tick_tups = list(self.iter_ticks()) # iter_ticks calls the locator
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/axis.py", line 967, in iter_ticks
majorLocs = self.major.locator()
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/ticker.py", line 1985, in __call__
return self.tick_values(vmin, vmax)
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/ticker.py", line 1993, in tick_values
locs = self._raw_ticks(vmin, vmax)
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/ticker.py", line 1932, in _raw_ticks
nbins = np.clip(self.axis.get_tick_space(),
File "/Users/michael/conda/envs/mpl/lib/python3.7/site-packages/matplotlib/axis.py", line 2159, in get_tick_space
return int(np.floor(length / size))
ValueError: cannot convert float NaN to integer
Activity
minor change as a global workaround for NNPDF/nnpdf#363 until matplot…
tacaswell commentedon Feb 13, 2019
We special case no artist, and handle the case of just one artist with an invalid bounding box, but fail on the case with only artists with invalid bounding boxes.
I'll have a PR in shortly.
Thanks for the extremely clear example (it is going to made into a test!).
Could not reproduce the
ValueErrorthough.FIX: bbox_inches='tight' with only non-finite bounding boxes
wilsonmr commentedon Feb 13, 2019
Thanks for the reply! Perhaps the
ValueErroris dependent on numpy version, otherwise I'm not sure. I'm getting it withnumpy 1.15.4 py37hacdab7b_0and
numpy-base 1.15.4 py37h6575580_0Full traceback in case it's more instructive:
FIX: bbox_inches='tight' with only non-finite bounding boxes
minor change as a global workaround for NNPDF/nnpdf#363 until matplot…
Revert "minor change as a global workaround for NNPDF/nnpdf#363 until m…
minor change as a global workaround for NNPDF/nnpdf#363 until matplot…