Skip to content

Creating colorbar for manual axes broken #10582

Closed
@dopplershift

Description

@dopplershift

This only occurs with 2.2rc1 (and the current tip of that branch). The following code:

import matplotlib.pyplot as plt
import numpy as np

gx = np.linspace(-5, 5, 10)
img = np.hypot(gx, gx[:, None])

fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
mesh = ax.pcolormesh(gx, gx, img)
plt.colorbar(mesh)

plt.show()

produces:

Traceback (most recent call last):
  File "test-error.py", line 10, in <module>
    plt.colorbar(mesh)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/pyplot.py", line 2225, in colorbar
    ret = gcf().colorbar(mappable, cax = cax, ax=ax, **kw)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/figure.py", line 2062, in colorbar
    cax, kw = cbar.make_axes(ax, **kw)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/colorbar.py", line 1135, in make_axes
    gs = parents[0].get_subplotspec().get_gridspec()
AttributeError: 'Axes' object has no attribute 'get_subplotspec'

The line in question:

# check if using constrained_layout:
gs = parents[0].get_subplotspec().get_gridspec()
using_constrained_layout = (gs._layoutbox is not None)

Seems to have crept in with the constrained layout manager--I'm not sure what the proper fix is.

Metadata

Metadata

Assignees

Labels

Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions