Skip to content

Commit 759d1e9

Browse files
committed
improve handling of (transparent) snapshots in IPython/Jupyter Notebooks
1 parent d7d2df7 commit 759d1e9

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

eomaps/eomaps.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3462,21 +3462,13 @@ def snapshot(self, *layer, transparent=False, clear=False):
34623462
else:
34633463
sn = self._get_snapshot()
34643464
try:
3465-
from IPython.display import display, Image as IpyImage
3466-
from io import BytesIO
3467-
3468-
# fix issues with PILLOW 10.0 and transparent snapshots
3469-
# in jupyter notebooks (TODO should be fixed in PILLOW 10.1.0)
3470-
# ...bug causes unwanted errors in _repr__jpeg_ for RGBA images
3471-
# the fix enforces png as format
3472-
temp = BytesIO()
3473-
Image.fromarray(sn, "RGBA").save(temp, format="png")
3474-
3475-
display(
3476-
IpyImage(temp.getvalue()),
3477-
display_id=True,
3478-
clear=clear,
3479-
)
3465+
from IPython.display import display_png, clear_output
3466+
3467+
if clear:
3468+
clear_output(wait=True)
3469+
# use display_png to avoid issues with transparent snapshots
3470+
display_png(Image.fromarray(sn, "RGBA"), raw=False)
3471+
34803472
except Exception:
34813473
_log.exception(
34823474
"Unable to display the snapshot... is the script "

0 commit comments

Comments
 (0)