v0.60 not compatible with seaborn v0.13
When using statannotations v0.60 with seaborn v0.13, it would fail with this error: AttributeError: module 'seaborn.categorical' has no attribute '_Violin(Box...)Plotter'
It only works with seaborn v0.11. Any fix for this would be very much appreciated!
Similar error here:
AttributeError: module 'seaborn.categorical' has no attribute '_BoxPlotter'
Thanks for the updates
Same issue here:
AttributeError: module 'seaborn.categorical' has no attribute '_BoxPlotter'
Same issue here:
code
from statannotations.Annotator import Annotator
x = "color"
y = "price"
hue = "cut"
hue_order=['Ideal', 'Premium', 'Good', 'Very Good', 'Fair']
order = ["E", "I", "J"]
pairs=[
(("E", "Ideal"), ("E", "Very Good")),
(("E", "Ideal"), ("E", "Premium")),
(("E", "Ideal"), ("E", "Good")),
(("I", "Ideal"), ("I", "Premium")),
(("I", "Ideal"), ("I", "Good")),
(("J", "Ideal"), ("J", "Premium")),
(("J", "Ideal"), ("J", "Good")),
(("E", "Good"), ("I", "Ideal")),
(("I", "Premium"), ("J", "Ideal")),
]
ax = sns.boxplot(data=df, x=x, y=y, order=order, hue=hue, hue_order=hue_order)
annot = Annotator(ax, pairs, data=df, x=x, y=y, order=order, hue=hue, hue_order=hue_order)
annot.configure(test='Mann-Whitney', verbose=2)
annot.apply_test()
annot.annotate()
plt.legend(loc='upper left', bbox_to_anchor=(1.03, 1))
plt.show()
raise Exception
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[282], line 19
7 pairs=[
8 (("E", "Ideal"), ("E", "Very Good")),
9 (("E", "Ideal"), ("E", "Premium")),
(...)
16 (("I", "Premium"), ("J", "Ideal")),
17 ]
18 ax = sns.boxplot(data=df, x=x, y=y, order=order, hue=hue, hue_order=hue_order)
---> 19 annot = Annotator(ax, pairs, data=df, x=x, y=y, order=order, hue=hue, hue_order=hue_order)
20 annot.configure(test='Mann-Whitney', verbose=2)
21 annot.apply_test()
File ~/anaconda3/envs/pyG/lib/python3.8/site-packages/statannotations/Annotator.py:108, in Annotator.__init__(self, ax, pairs, plot, data, x, y, hue, order, hue_order, engine, verbose, **plot_params)
106 self._plotter = None
107 else:
--> 108 self._plotter = self._get_plotter(engine, ax, pairs, plot, data,
109 x, y, hue, order, hue_order,
110 verbose=verbose, **plot_params)
112 self._test = None
113 self.perform_stat_test = None
File ~/anaconda3/envs/pyG/lib/python3.8/site-packages/statannotations/Annotator.py:784, in Annotator._get_plotter(engine, *args, **kwargs)
782 if engine_plotter is None:
783 raise NotImplementedError(f"{engine} engine not implemented.")
--> 784 return engine_plotter(*args, **kwargs)
File ~/anaconda3/envs/pyG/lib/python3.8/site-packages/statannotations/_Plotter.py:87, in _SeabornPlotter.__init__(self, ax, pairs, plot, data, x, y, hue, order, hue_order, verbose, **plot_params)
85 self.check_plot_is_implemented(plot)
86 self.plot = plot
---> 87 self.plotter = self._get_plotter(plot, x, y, hue, data, order,
88 hue_order, **plot_params)
90 self.group_names, self.labels = self._get_group_names_and_labels()
91 self.groups_positions = _GroupsPositions(self.plotter,
92 self.group_names)
File ~/anaconda3/envs/pyG/lib/python3.8/site-packages/statannotations/_Plotter.py:119, in _SeabornPlotter._get_plotter(self, plot, x, y, hue, data, order, hue_order, **plot_params)
116 self.fix_and_warn(dodge, hue, plot)
118 if plot == 'boxplot':
--> 119 plotter = sns.categorical._BoxPlotter(
120
121 x, y, hue, data, order, hue_order,
122 orient=plot_params.get("orient"),
123 width=plot_params.get("width", 0.8),
124 dodge=True,
125 fliersize=plot_params.get("fliersize", 5),
126 linewidth=plot_params.get("linewidth"),
127 saturation=.75, color=None, palette=None)
129 elif plot == 'swarmplot':
130 plotter = sns.categorical._SwarmPlotter(
131 x, y, hue, data, order, hue_order,
132 orient=plot_params.get("orient"),
133 dodge=True, color=None, palette=None)
AttributeError: module 'seaborn.categorical' has no attribute '_BoxPlotter'
It need older version
import statannotations,matplotlib
sns.__version__,statannotations.__version__,matplotlib.__version__
>>> ('0.11.2', '0.5.0', '3.7.1')
and pip install statannotations==0.5.0,It works fine using the above code~~~
@trevismd Any plans to keep this project going? Thanks for the work!
This is a much-needed package! Please update so it can be used with the latest Seaborn. Thank you!
You could use the package starbars. You give the pairs and their p-value, and it draws it for you! It also has an option not to show non-significant p-value bars.
You can find the starbars documentation here. Hope it helps! :)
Disclaimer: I'm the author of the package.
You could use the package
starbars. You give the pairs and their p-value, and it draws it for you! It also has an option not to show non-significant p-value bars.You can find the starbars documentation here. Hope it helps! :)
Disclaimer: I'm the author of the package.
How to label significance for a boxplot containing hue? How to use different inspection methods(ttest or ...)?
Hey, sorry for the late reply!
I hadn't thought about the hue case, so thank you for pointing it out to me! I'll try to find a solution for that too.
Regarding the statistical methods, for now I haven't included it in the function, so you'd have to find the p-values with your chosen statistics separetely and then save the results in a tuple with the variables' names (var1, var2, pvalue).
Here's an example:
values_dict = {
'A': [1, 2, 3, 4, 5],
'B': [2, 3, 4, 5, 6],
'C': [3, 4, 5, 6, 7]
}
annotations = []
keys = list(values_dict.keys())
# Perform t-test for each pair of variables
for i in range(len(keys)):
for j in range(i + 1, len(keys)):
key1 = keys[i]
key2 = keys[j]
values1 = values_dict[key1]
values2 = values_dict[key2]
t_stat, p_value = stats.ttest_ind(values1, values2)
annotations.append((key1, key2, p_value))
values = [values_dict[key] for key in keys]
# Create a boxplot
plt.boxplot(values, tick_labels=keys, patch_artist=True)
starbars.draw_annotation(annotations)
plt.show()
Hope it helps and feel free to ask for more :)
You could use the package
starbars. You give the pairs and their p-value, and it draws it for you! It also has an option not to show non-significant p-value bars. You can find the starbars documentation here. Hope it helps! :) Disclaimer: I'm the author of the package.How to label significance for a boxplot containing hue? How to use different inspection methods(ttest or ...)?
heyhey! Just checking in to say that the new 1.3.0 version of starbars allows you to use hues as labels. You'd just need to specify the hue label and group in a further tuple such as: ((hue_label1, group1), (hue_label2, group2), pvalue).
Check out the new documentation for more info and I'm always available for more help ✨