Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Open
@komoto48g

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions