Closed as not planned
Description
For a package I am developing, I need to clip and image (shown with imshow) in display coordinates. Clipping seems to work fine in pixel coordinates:
import numpy as np
from matplotlib.lines import Path
from matplotlib.patches import PathPatch
import matplotlib.pyplot as plt
x = [0.3, 0.6, 0.6, 0.3, 0.3]
y = [0.3, 0.3, 0.6, 0.6, 0.3]
np.random.seed(12345)
image = np.random.random((12,12))
data = np.vstack([x, y]).transpose()
path = Path(np.vstack(data))
poly = PathPatch(path, edgecolor='red', facecolor='none')
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.add_patch(poly)
im = ax.imshow(image, extent=[0., 1., 0., 1.], interpolation='nearest')
im.set_clip_path(poly)
fig.savefig('test1.png')
but not in display coordinates:
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.add_patch(poly)
im = ax.imshow(image, extent=[0., 1., 0., 1.], interpolation='nearest')
display = ax.transData.transform(data)
path_display = Path(display)
poly_display = PathPatch(path_display, transform=None)
im.set_clip_path(poly_display)
fig.savefig('test2.png')
Is this a bug, or am I doing this incorrectly?
Metadata
Metadata
Assignees
Labels
No labels