trevismd / statannotations

add statistical significance annotations on seaborn plots. Further development of statannot, with bugfixes, new features, and a different API.
Other
619 stars 67 forks source link

v0.60 not compatible with seaborn v0.13 #143

Open xinwei-sher opened 5 months ago

xinwei-sher commented 5 months ago

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!

moqri commented 4 months ago

Similar error here:

AttributeError: module 'seaborn.categorical' has no attribute '_BoxPlotter'

Thanks for the updates

pfluec commented 4 months ago

Same issue here:

AttributeError: module 'seaborn.categorical' has no attribute '_BoxPlotter'

wenyuhaokikika commented 3 months ago

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'
wenyuhaokikika commented 3 months ago

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~~~

mahlzahn commented 3 months ago

@trevismd Any plans to keep this project going? Thanks for the work!

xinwei-sher commented 2 months ago

This is a much-needed package! Please update so it can be used with the latest Seaborn. Thank you!