Closed
Description
Bug summary
When calling remove()
on a colorbar that belongs to a constrained layout, subsequent plt.show()
call produces a traceback, without showing anything in the plot.
The scenario worked in version 3.3.4, the error appeared first in 3.4.0.
Code for reproduction
import matplotlib.pyplot as plt
import numpy as np
figure, axes = plt.subplots(1, 1, constrained_layout=True)
data = np.random.normal(size=(10,10))
im = axes.imshow(data)
colorbar = figure.colorbar(im, ax=axes)
colorbar.remove()
plt.show()
Actual outcome
Traceback (most recent call last):
File "C:\Users\mfrodl\Envs\myenv\lib\site-packages\matplotlib\backends\backend_qt5.py", line 475, in _draw_idle
self.draw()
File "C:\Users\mfrodl\Envs\myenv\lib\site-packages\matplotlib\backends\backend_agg.py", line 406, in draw
self.figure.draw(self.renderer)
File "C:\Users\mfrodl\Envs\myenv\lib\site-packages\matplotlib\artist.py", line 74, in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
File "C:\Users\mfrodl\Envs\myenv\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\mfrodl\Envs\myenv\lib\site-packages\matplotlib\figure.py", line 2781, in draw
self.execute_constrained_layout(renderer)
File "C:\Users\mfrodl\Envs\myenv\lib\site-packages\matplotlib\figure.py", line 3122, in execute_constrained_layout
do_constrained_layout(fig, renderer, h_pad, w_pad, hspace, wspace)
File "C:\Users\mfrodl\Envs\myenv\lib\site-packages\matplotlib\_constrained_layout.py", line 109, in do_constrained_layout
_make_layout_margins(fig, renderer, h_pad=h_pad, w_pad=w_pad,
File "C:\Users\mfrodl\Envs\myenv\lib\site-packages\matplotlib\_constrained_layout.py", line 241, in _make_layout_margins
cbpos, cbbbox = _get_pos_and_bbox(cbax, renderer)
File "C:\Users\mfrodl\Envs\myenv\lib\site-packages\matplotlib\_constrained_layout.py", line 451, in _get_pos_and_bbox
pos = pos.transformed(fig.transSubfigure - fig.transFigure)
AttributeError: 'NoneType' object has no attribute 'transSubfigure'
Expected outcome
Plot window with the image, without colorbar.
Operating system
Windows 10
Matplotlib Version
3.4.3
Matplotlib Backend
Qt5Agg
Python version
3.8.3
Jupyter version
No response
Other libraries
No response
Installation
pip
Conda channel
No response