Skip to content

Cannot generate colour bar for Axes attached to mpl.figure.Figure

Attempting to create a GWpy colourbar for an Axes attached directly to a matplotlib.figure.Figure (rather than a gwpy.plot.Plot) fails in a fairly incomprehensible way:

>>> import gwpy
>>> import numpy
>>> from matplotlib import pyplot
>>> data = numpy.random.rand(100, 100)
>>> fig = pyplot.figure()
>>> ax = fig.gca()
>>> ax.imshow(data)
>>> ax.colorbar()
  File "/home/duncan/opt/mambaforge/envs/py311/lib/python3.11/site-packages/matplotlib/figure.py", line 163, in update
    raise ValueError('left cannot be >= right')
ValueError: left cannot be >= right

This was introduced by 73b5ef06, which hasn't been released yet.