wjm41 / molplotly

add-on to plotly which show molecule images on mouseover!
Apache License 2.0
242 stars 25 forks source link

Error when using with Plotly Subplots #21

Open matthewtoholland opened 2 years ago

matthewtoholland commented 2 years ago

When trying to use molplotly to generate hover structures with a series of scatterplots generated using make_subplots (generated using different columns of a dataframe for the same RDKit molecule row), molplotly.add_molecules returns

ValueError: More than one plotly curve in figure - color_col and/or marker_col needs to be specified.

As these plots are generated using different columns, rather than faceting data in a single column based on values in another, there is no common color or marker column. Is there a way to generate molecular structures for these subplots?

wjm41 commented 1 year ago

Hey, thanks for the question! Could you provide a toy example in code of what you'd like to plot? I'll try to have a look over the weekend :)

matthewtoholland commented 1 year ago

Sure, please find attached the test data. What I am looking for is a scatter plot faceted by the 'variable' column (so should be three plots), where the structures are revealed on hovering. I have included a code snippet below!

data = pd.read_csv('test_data.csv')
plot = px.scatter(data, x='value', y='Assay', facet_col='variable', hover_name='variable')
plot.update_xaxes(range=[1.0, 0.6])
plot.update_yaxes(range=[2.5, 0])

test_data.csv

Thank you!

wjm41 commented 1 year ago

Hey, sorry for the delay - I've updated the package and it should be able to handle data faceting now. Could you install the latest version with pip install molplotly==1.1.5 and see if that works for you? :D

I haven't tested make_subplots yet but if it's just using facet_col in scatter it should work. I've included your example data at the end of examples/simple_usage_and_formatting.ipynb to showcase it working!