[ENH]: Remove artists from axes completely. · Issue #25168 · matplotlib/matplotlib · GitHub
Skip to content

[ENH]: Remove artists from axes completely. #25168

Description

@komoto48g

Problem

Calling art.remove() doesn't seem to completely detach the art from the original axes.
In the following sample code, when removing the art from axes (say ax1) and adding it to other axes (say ax2), the ax2 will not draw the art.

import numpy as np
from matplotlib import patches
from matplotlib import pyplot as plt

data = np.random.rand(5,5)

fig = plt.figure()
ax1, ax2 = fig.subplots(1,2)
ax1.imshow(data, interpolation='nearest', cmap='gray',)
ax2.imshow(data, interpolation='bilinear', cmap='gray',)
if 1:
    art = patches.Circle((2, 2), 2, fill=0)
    ax1.add_artist(art)
    art.remove()
    ax2.add_artist(art)
plt.show()

This issue was raised on: Discrouse matplotlib.

Proposed solution

The following line is suggested to be added after `art.remove()':

art.set_transform(ax2.transData)

or

art._transformSet = False

should be added in the art.remove method.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions