Fine tuning your Jupyter notebook's displays

[ #rdkit #python #jupyter ]

08 April 2022 - Cédric Bouysset

Card image cap

One of the nice things about Jupyter notebooks is that some objects come with a more visual and practical representation when you put them at the last line of a cell. For example, RDKit displays an image of the molecule, and pandas displays a pretty table view of the dataframe.

In this blog post, I’ll show you how to create your own display methods for your classes, and we’ll even take it a step further with custom representations for built-in types such as str or list, and how to enable them for all your notebooks.

Here’s a gist to my own startup profile:

For the final wow factor, I’ll just leave this abomination here:

If you want to reproduce this (why would you ever want to do that?), you’ll have to use the text/plain output which uses a slightly different syntax from previous examples, but it has the advantage of working in IPython shells in addition to notebooks.

This concludes the blog post, hope you liked it!