Description
Bug report
Bug summary
A recent upgrade to matplotlib 2.2.3 causes a crash when the following conditions are true:
- plot empty lists
- rasterized=True
- savefig to pdf.
Code for reproduction
import numpy as np
from matplotlib.pyplot import *
x = np.random.normal(0,1,5000)
y = np.random.normal(0,1,5000)
ax = subplot(111)
inds = np.where(x > 10)[0]
ax.plot(x[inds],y[inds],'b.',rasterized=True) # if rasterized=False, the code runs
ax.plot(x,y,'g.',rasterized=True)
savefig("bug.png") #works regardless
savefig("bug.pdf",format='pdf',dpi=300)
show()
Actual outcome
Traceback (most recent call last):
File "bug.py", line 16, in <module>
savefig("bug.pdf",format='pdf',dpi=300)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 695, in savefig
res = fig.savefig(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 2062, in savefig
self.canvas.print_figure(fname, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 2263, in print_figure
**kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.py", line 2586, in print_pdf
self.figure.draw(renderer)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 1493, in draw
renderer, self, artists, self.suppressComposite)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 2635, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 60, in draw_wrapper
renderer.stop_rasterizing()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_mixed.py", line 130, in stop_rasterizing
buffer, bounds = self._raster_renderer.tostring_rgba_minimized()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 144, in tostring_rgba_minimized
return np.array(region), extents
ValueError: negative dimensions are not allowed
Expected outcome
When this previously ran prior to upgrading various libraries, everything worked and I obtained both a png and pdf file. Note above that the code works in saving to a png regardless of whether rasterized=True or not.
I am not explicitly trying to feed empty lists into plot, but I use numpy.where to see what indices need to be plotted. So for now I can just see if len(inds) == 0 or not, and my code works. But I figured I'd pass this along anyway. I don't quite recall the matplotlib version I was using, but it was I either 2.0 or 2.1. I upgraded to 2.2 to use the cividis colormap.
Matplotlib version
- Operating system: Linux Mint 18.3 Cinnamon 64-bit
- Matplotlib version: 2.2.3
- Matplotlib backend (
print(matplotlib.get_backend())
): TkAgg - Python version: 2.7.12
- Other libraries: Numpy 1.15.0
All python packages installed via source or pip.