Skip to content

[Bug]: Crash when removing a subfigure with a subplot in a figure #31319

@williamlus

Description

@williamlus

Bug summary

The program crashes with "AttributeError: 'list' object has no attribute '_mouseover_set'" when I create a figure with subfigures, create subplots in the subfigures, and remove a subfigure.

Code for reproduction

import matplotlib.pyplot as plt

fig = plt.figure()
subfigs = fig.subfigures(1, 2)
subfigs[0].subplots()
subfigs[0].remove()

Actual outcome


AttributeError Traceback (most recent call last)
Cell In[2], line 8
6 subfigs[0].subplots()
7 subfigs[1].subplots()
----> 8 subfigs[0].remove()

File ~/dataviz-render-update-testing/matplotlib/lib/matplotlib/artist.py:260, in Artist.remove(self)
257 _ax_flag = False
258 if hasattr(self, 'axes') and self.axes:
259 # remove from the mouse hit list
--> 260 self.axes._mouseover_set.discard(self)
261 self.axes.stale = True
262 self.axes = None # decouple the artist from the Axes

AttributeError: 'list' object has no attribute '_mouseover_set'

Expected outcome

No crash.

Additional information

No response

Operating system

No response

Matplotlib Version

0.2.0.dev53882+unknown.g607d2c380.g02b42db27

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions