Skip to content

calling annotate with nan values for the position still gives error after 3.0.2 #13276

@wilsonmr

Description

@wilsonmr

Bug report

Bug summary

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:

import matplotlib.pyplot as plt

fig, 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 thrown
ax.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

plt.tight_layout()
plt.savefig("bar.png")

which does work as per the #12651

Matplotlib version

  • Operating system: OSX, but also tested on linux
  • Matplotlib version: 3.0.2
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg
  • Python version: 3.7.2

(conda installation)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions