I'm trying to run this very simple example from numpy page regarding histogram2d:
https://numpy.org/doc/stable/reference/generated/numpy.histogram2d.html.
from matplotlib.image import NonUniformImage
import matplotlib.pyplot as plt
xedges = [0, 1, 3, 5]
yedges = [0, 2, 3, 4, 6]
x = np.random.normal(2, 1, 100)
y = np.random.normal(1, 1, 100)
H, xedges, yedges = np.histogram2d(x, y, bins=(xedges, yedges))
H = H.T
fig = plt.figure(figsize=(7, 3))
ax = fig.add_subplot(131, title='imshow: square bins')
plt.imshow(H, interpolation='nearest', origin='lower',extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])
ax = fig.add_subplot(132, title='pcolormesh: actual edges',aspect='equal')
X, Y = np.meshgrid(xedges, yedges)
ax.pcolormesh(X, Y, H)
ax = fig.add_subplot(133, title='NonUniformImage: interpolated',aspect='equal', xlim=xedges[[0, -1]], ylim=yedges[[0, -1]])
im = NonUniformImage(ax, interpolation='bilinear')
xcenters = (xedges[:-1] + xedges[1:]) / 2
ycenters = (yedges[:-1] + yedges[1:]) / 2
im.set_data(xcenters,ycenters,H)
ax.images.append(im)
plt.show()
By running this code as in the example, I receive the error
cannot unpack non-iterable NoneType object
This happens as soon as I run the line ax.images.append(im).
Does anyone know why this happens?
Tried to run an example from numpy website and doesn't work as expected.

The full error message is:
The error occurs deep in the
appendcall, and appears to involve trying to get information about the plot window. If I comment out theappendline, and it continues on to theplt.show(), and resulting image looks like the example, except the third image is blank.I tested this in a Windows
QtConsole; I don't know if that context posses problems for thisappendor not. I don't think it's a problem with your code copy.