Description
Bug report
Bug summary
Calling pyplot.show()
with TkAgg backend on x86 machine raises OverflowError
.
The format provided to PyArg_ParseTuple
in mpl_tk_blit()
in file _tkagg.cpp ("ns(iin)(iiii)(iiii):blit"
) causes the third element in the third argument to blit()
(dataptr[2]
) to convert to a Py_ssize_t
. A 32-bit Py_ssize_t
will not accommodate a value greater than or equal to 2^31. I consistently see values outside this range for the third element in dataptr
(see PDB output below).
Changing iin
in the format to iik
(dataptr[2]
to unsigned long
) fixes this problem for me but it may cause problems under other conditions or architectures.
Code for reproduction
from matplotlib import pyplot as plt
x = [1, 2, 3, 4]
y = [1, 4, 9, 16]
plt.plot(x, y)
plt.show()
Actual outcome
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/local/lib/python3.7/tkinter/__init__.py", line 1702, in __call__
return self.func(*args)
File "/usr/local/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py", line 267, in resize
self.draw()
File "/usr/local/lib/python3.7/site-packages/matplotlib/backends/backend_tkagg.py", line 10, in draw
_backend_tk.blit(self._tkphoto, self.renderer._renderer, (0, 1, 2, 3))
File "/usr/local/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py", line 91, in blit
photoimage.tk.interpaddr(), str(photoimage), dataptr, offsets, bboxptr)
OverflowError: Python int too large to convert to C ssize_t
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/local/lib/python3.7/tkinter/__init__.py", line 1702, in __call__
return self.func(*args)
File "/usr/local/lib/python3.7/tkinter/__init__.py", line 746, in callit
func(*args)
File "/usr/local/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py", line 346, in idle_draw
self.draw()
File "/usr/local/lib/python3.7/site-packages/matplotlib/backends/backend_tkagg.py", line 10, in draw
_backend_tk.blit(self._tkphoto, self.renderer._renderer, (0, 1, 2, 3))
File "/usr/local/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py", line 91, in blit
photoimage.tk.interpaddr(), str(photoimage), dataptr, offsets, bboxptr)
OverflowError: Python int too large to convert to C ssize_t
Arguments to blit() from PDB:
> /usr/local/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py(91)blit()
-> photoimage.tk.interpaddr(), str(photoimage), dataptr, offsets, bboxptr)
(Pdb) p photoimage.tk.interpaddr()
170396608
(Pdb) p str(photoimage)
'pyimage10'
(Pdb) p dataptr
(480, 640, 2990080008)
(Pdb) p offsets
(0, 1, 2, 3)
(Pdb) p bboxptr
(0, 640, 0, 480)
Expected outcome
A graph mapping [1, 2, 3, 4] to [1, 4, 9, 16].
Matplotlib version
- Operating system: Slackware Linux 14.2, kernel 4.4.157
- Matplotlib version: 3.0.0 (via pip)
- Matplotlib backend (
print(matplotlib.get_backend())
): TkAgg - Python version: 3.7.0 (from source, compiled with gcc)
- Jupyter version (if applicable):
- Other libraries: numpy 1.15.2