You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://www.rdkit.org/)
`molplotly` is an add-on to `plotly` built on RDKit which allows 2D images of molecules to be shown in `plotly` figures when hovering over the datapoints.
6
+
`molplotly` is an add-on to `plotly` built on RDKit which allows 2D images of molecules to be shown in `plotly` figures when hovering over the data points.
➡️ A readable walkthrough of how to use the package together with some useful examples can be found in [this blog post](https://www.wmccorkindale.com/post/introducing-molplotly) while a runnable notebook can be found in `example.ipynb` :)
16
12
13
+
## ⬇️ Installation
14
+
15
+
```sh
16
+
pip install molplotly
17
+
conda install rdkit
18
+
```
19
+
17
20
## 📜 Usage
18
21
19
22
```python
@@ -31,62 +34,70 @@ df_esol['y_true'] = df_esol['measured log solubility in mols per litre']
31
34
fig = px.scatter(df_esol, x="y_true", y="y_pred")
32
35
33
36
# add molecules to the plotly graph - returns a Dash app
34
-
app = molplotly.add_molecules(fig=fig,
35
-
df=df_esol,
36
-
smiles_col='smiles',
37
-
title_col='Compound ID',
37
+
app = molplotly.add_molecules(fig=fig,
38
+
df=df_esol,
39
+
smiles_col='smiles',
40
+
title_col='Compound ID',
38
41
)
39
42
40
43
# run Dash app inline in notebook (or in an external server)
a plotly figure object containing datapoints plotted from df
46
-
*`df` : pandas.DataFrame object\
51
+
52
+
-`df` : pandas.DataFrame object\
47
53
a pandas dataframe that contains the data plotted in fig
48
-
*`smiles_col` : str, optional\
54
+
-`smiles_col` : str, optional\
49
55
name of the column in df containing the smiles plotted in fig (default 'SMILES')
50
-
*`show_img` : bool, optional\
56
+
-`show_img` : bool, optional\
51
57
whether or not to generate the molecule image in the dash app (default True)
52
-
*`title_col` : str, optional\
58
+
-`title_col` : str, optional\
53
59
name of the column in df to be used as the title entry in the hover box (default None)
54
-
*`show_coords` : bool, optional\
60
+
-`show_coords` : bool, optional\
55
61
whether or not to show the coordinates of the data point in the hover box (default True)
56
-
*`caption_cols` : list, optional\
62
+
-`caption_cols` : list, optional\
57
63
list of column names in df to be included in the hover box (default None)
58
-
*`caption_transform` : dict, optional\
64
+
-`caption_transform` : dict, optional\
59
65
Functions applied to specific items in all cells. The dict must follow a key: function structure where the key must correspond to one of the columns in subset or tooltip. (default {})
60
-
*`color_col` : str, optional\
66
+
-`color_col` : str, optional\
61
67
name of the column in df that is used to color the datapoints in df - necessary when there is discrete conditional coloring (default None)
62
-
*`wrap` : bool, optional\
68
+
-`wrap` : bool, optional\
63
69
whether or not to wrap the title text to multiple lines if the length of the text is too long (default True)
64
-
*`wraplen` : int, optional\
70
+
-`wraplen` : int, optional\
65
71
the threshold length of the title text before wrapping begins - adjust when changing the width of the hover box (default 20)
66
-
*`width` : int, optional\
72
+
-`width` : int, optional\
67
73
the width in pixels of the hover box (default 150)
68
-
*`fontfamily` : str, optional\
74
+
-`fontfamily` : str, optional\
69
75
the font family used in the hover box (default 'Arial')
70
-
*`fontsize` : int, optional\
76
+
-`fontsize` : int, optional\
71
77
the font size used in the hover box - the font of the title line is fontsize+2 (default 12)
72
-
78
+
73
79
#### Output parameters
80
+
74
81
by default a JupyterDash `app` is returned which can be run inline in a jupyter notebook or deployed on a server via `app.run_server()`
75
82
76
-
* The recommended `height` of the app is `50+(height of the plotly figure)`.
77
-
* For the `port` of the app, make sure you don't pick the same `port` as another `molplotly` plot otherwise the tooltips will clash with each other!
83
+
- The recommended `height` of the app is `50+(height of the plotly figure)`.
84
+
- For the `port` of the app, make sure you don't pick the same `port` as another `molplotly` plot otherwise the tooltips will clash with each other!
78
85
79
86
## 💻 Can I run this in colab?
87
+
80
88
JupyterDash is supposed to have support for Google Colab but at some point that seems to have broken... Keep an eye on the raised issue [here](https://github.com/plotly/jupyter-dash/issues/10)!
81
89
82
90
## 💾 Can I save these plots?
91
+
83
92
`moltplotly` works using a Dash app which is non-trivial to export because server side javascript is needed in addition to HTML/CSS styling ([as detailed here](https://stackoverflow.com/questions/60097577/how-to-export-a-plotly-dashboard-app-into-a-html-standalone-file-to-share-with-t))
84
93
85
94
Until I find a way to get around that, the best alternative is exporting the plotly figure without molecules showing :( as detailed in this [page](https://plotly.com/python/interactive-html-export/). If you want to use it in a presentation I'd suggest keeping the figure open in a browser and changing windows to it during your talk!
86
95
87
-
## 🛑 Warning about memory size
96
+
## 🛑 Warning about memory size
97
+
88
98
Just adding a warning here that memory usage in a notebook can increase significanly when using plotly (not `molplotly`'s fault!). If you notice your jupyter notebook slowing down, plotly itself is a likely culprit... In that case I'd consider either using plotly with [static image rendering](https://plotly.com/python/renderers/#static-image-renderers), or ... use [seaborn](https://seaborn.pydata.org/index.html):P
0 commit comments