RDKit Mols in altair plots

Repo
Notebook

I recently came across a great looking library called molplotly. It uses plotly to show small pictures (aka tooltips) of the molecule associated with a scatterplot point on mouse-over. Along with mols2grid, it's a great way to parse data or share it collaboratively to an audience.

Below I demonstrate an alternative using altair. Altair visualizations look great, although there's a steep learning curve unless you're already familiar with the 'grammar of graphics' a la ggplot. There's a bit of tinkering to set up each plot, but at the same time there's a lot of freedom to customize each visualization as shown below.

The notebook uses a sample of drug-like ligands from the RCSB Ligand Expo with clogp, molwt, and tpsa values along with some fake potency data. The main trick to get image tooltips is to add a column to the input dataframe that specifies a URL path to each ligand's image file (which have to be generated beforehand). Beware that in notebooks, the image path will be relative to the notebook server rather than the filesystem.

Scatter plot of MolWt. vs cLogP

Below demonstrates plotting three dimensions (molwt, clogp, and potency as colour) along with tooltips, which appear on a mouse-over.

Horizontal scatterplot with molecules in yaxis labels

Below demonstrates the ability to encode two types of images: one in the y-axis labels, and a different one in the tooltips. This might be useful for comparing two sets of molecules or, alternatively, putting 2D structures in the axis and 3D structures of binding modes in the tooltip.