statannotations
statannotations copied to clipboard
AttributeError: 'tuple' object has no attribute '__module__' when using plot_and_annotate_facets
Hi, after I defined the plot_and_annotate_facets function, there's one AttributeError: 'tuple' object has no attribute 'module' from g.map function. I found plot_and_annotate_facets is a tuple. Could you please tell me if I am using this function correctly or not? Thank you very much!
annot = Annotator(None, pairs)
plot_and_annotate_facets = annot.plot_and_annotate_facets(
plot='boxplot', plot_params=plot_params, configuration=configuration, annotation_func='set_custom_annotations', annotation_params=annotation_params, **kwargs)
g = sns.FacetGrid(
plot_df,
col="Cell type"
)
g.map(
plot_and_annotate_facets,
feature_name, # x
value_name, # y
)
Hello @xinyuejohn , thank you for the question. Sorry this is yet poorly documented, and part 2 of the tutorial is long overdue... (There is an example in the test suite: https://github.com/trevismd/statannotations/blob/2a5ebe1a4d90c641552db580f3f285559e1bb277/tests/test_integrate_annotator.py#L73-L87)
So basically should be using g.map_dataframe
instead of g.map
(this should really be in the docstring, I'm sorry), and thus provide the arguments directly to that function.
For your snippet, something like this:
annot = Annotator(None, pairs)
plot_and_annotate_facets = annot.plot_and_annotate_facets(
# deducing
plot_params = {
'x': feature_name,
'y': value_name
}
g = sns.FacetGrid(
data=plot_df,
col="Cell type"
)
g.map_dataframe(
annot.plot_and_annotate_facets,
plot='boxplot',
plot_params=plot_params,
configuration=configuration,
annotation_func='set_custom_annotations',
annotation_params=annotation_params,
**kwargs
)
Please let us know if something is still not working.
Hello @xinyuejohn , thank you for the question. Sorry this is yet poorly documented, and part 2 of the tutorial is long overdue... (There is an example in the test suite:
https://github.com/trevismd/statannotations/blob/2a5ebe1a4d90c641552db580f3f285559e1bb277/tests/test_integrate_annotator.py#L73-L87
) So basically should be using
g.map_dataframe
instead ofg.map
(this should really be in the docstring, I'm sorry), and thus provide the arguments directly to that function.
@trevismd Thank you so much for your reply! Your reply really helped a lot. But I still have some issue about pairs.
For example, in your test suite, you used self.simple_pairs as pairs. But if I want to only plot for some of the pairs ([(("a", "blue"), ("b", "blue"))]) instead of [["a", "b"]], I will get an error: Missing x value(s) "('a', 'blue')", "('b', 'blue')"
in x (specified in pairs
) in data
Could you please tell me if I can use such pairs when I plot? Thank you so much!
hello @trevismd. you have here a great tool that a lot are interested in, however, it is not documented well. I find it a complete waste of time running between the different parts of codes/informations you gave for each comment trying hard to link them together. Would it be possible to provide a working example, from start to end, well documented, for adding annotations to catplot (grouped box plot output)? many thanks
after 2h I managed to came over the following... https://github.com/trevismd/statannotations/issues/36#issuecomment-1866210714 I still see a detailed doc will help with tweaking this amazing tool (e.g. between group stat rather than within group stat from catplot output, and more...)