Skip to content

Add IPython display support#389

Merged
jwiggins merged 9 commits into
masterfrom
enh/ipython-support
Mar 15, 2021
Merged

Add IPython display support#389
jwiggins merged 9 commits into
masterfrom
enh/ipython-support

Conversation

@corranwebster
Copy link
Copy Markdown
Contributor

@corranwebster corranwebster commented Feb 15, 2020

This PR adds two things:

  • IPython/Jupyter Notebook support for the SVG, Agg and Celiagg backends (using _repr_svg_ and _repr_png_ respectively).
  • a new to_image method for Agg and Celiagg backends which generates a PIL/Pillow Image object from the GC.

It also includes a drive-by fix for saving RGBA vs. BGRA format Celiagg graphics contexts, which fixes #304.

@jwiggins
Copy link
Copy Markdown
Member

This will need to be rebased to account for the recent removal of kiva.compat. Also, #304 has been fixed by #592 (also a drive-by fix there...). And once #590 goes in, there might be some similar changes that can happen here.

Other than the image data in the example notebook, I have no big issues with this change.

@jwiggins jwiggins force-pushed the enh/ipython-support branch from dc407ac to 35c9bdd Compare February 22, 2021 12:44
@corranwebster
Copy link
Copy Markdown
Contributor Author

This now has tests, so presuming test pass OK, this is probably ready for a proper review.

Copy link
Copy Markdown
Member

@jwiggins jwiggins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please strip the data out of the notebook before merging.

Comment thread kiva/celiagg.py
Comment on lines +875 to +886
pixels = self.gc.array
if self.pix_format.startswith('bgra'):
# Data is BGRA; Convert to RGBA
data = np.empty(pixels.shape, dtype=np.uint8)
data[..., 0] = pixels[..., 2]
data[..., 1] = pixels[..., 1]
data[..., 2] = pixels[..., 0]
data[..., 3] = pixels[..., 3]
else:
data = pixels

return Image.fromarray(data, 'RGBA')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It hasn't been a problem yet, but we might want to add support for formats without alpha at some point.

Comment thread kiva/examples/kiva/Kiva Explorer.ipynb Outdated
@jwiggins jwiggins merged commit c2cf958 into master Mar 15, 2021
@jwiggins jwiggins deleted the enh/ipython-support branch March 15, 2021 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Celiagg backend doesn't save images correctly

2 participants