Skip to content

Commit ba5640e

Browse files
committed
ImageEffect can have invisible_if_nill_clip_path option
1 parent d13b0c2 commit ba5640e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

mpl_visual_context/image_box.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,12 @@ def __init__(self, extent=None, bbox=None, coords="data", axes=None,
202202
blend_color=None, **im_kw):
203203
self.coords = coords
204204
self.bbox_orig = self._get_bbox_orig(extent, bbox)
205+
if "interpolation" not in im_kw:
206+
im_kw["interpolation"] = "none"
205207
BboxImage.__init__(
206208
self,
207209
Bbox([[0, 0], [0, 0]]),
208210
origin="lower",
209-
interpolation="none",
210211
transform=IdentityTransform(),
211212
**im_kw,
212213
)

mpl_visual_context/patheffects_image_effect.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,15 @@ def get_rendered_image(self):
138138

139139

140140
class ImageEffect(AbstractPathEffect, ImageEffectBase):
141-
def __init__(self, image_effect, clip_path_getter=None):
141+
def __init__(self, image_effect, clip_path_getter=None,
142+
invisible_if_nill_clip_path=True):
142143
"""
143144
144145
clip_path_getter: set the clip_path of the resulting image. Need to be a callable
145146
or an object with get_clip_path method, which returns a path and a transform.
147+
148+
invisible_if_nill_clip_path: if clip_path_getter is used and if it retune a
149+
nil path of length 0, do not draw the image. Default is True.
146150
"""
147151
if clip_path_getter is None or hasattr(clip_path_getter, "get_clip_path") or callable(clip_path_getter):
148152
self._clip_path_getter = clip_path_getter
@@ -153,6 +157,7 @@ def __init__(self, image_effect, clip_path_getter=None):
153157

154158
self._image_effect = image_effect
155159
self._path_effect = None
160+
self._invisible_if_nill_clip_path = invisible_if_nill_clip_path
156161

157162
def __ror__(self, other: AbstractPathEffect):
158163
e = ImageEffect(self._image_effect)
@@ -190,6 +195,10 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
190195
else:
191196
raise ValueError("clip_path_getter need to be a callable or an object with get_clip_path method.")
192197

198+
if self._invisible_if_nill_clip_path and len(clip_path) == 0:
199+
self.clear()
200+
return
201+
193202
pp = TransformedPath(clip_path, affine)
194203

195204
gc.set_clip_path(pp)

0 commit comments

Comments
 (0)