trevismd / statannotations

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

Annotation position misalignment #57

Open inqlee0704 opened 2 years ago

inqlee0704 commented 2 years ago

Hi! I first appreciate your efforts to make this amazing python library for plotting. I tried to use this tool to make some plots with annotations, but I encountered an issue that I couldn't fix. Annotations do not align for multiple annotations. Here is the image.

image

I tried to adjust the ylim, but it doesn't work.

image

Below is my code. `plt.figure(figsize=(15,8)) ax = sns.boxplot(x=x,y=y, hue=hue,data=df,fliersize=0,saturation=0.7)

plt.legend(bbox_to_anchor=(1.02, 1), loc='upper left', borderaxespad=0) annotator = Annotator(ax, pairs_all,x=x,y=y, hue=hue, data=df,verbose=False)

annotator.configure(text_format="star",loc='inside', verbose=False) annotator.set_pvalues(p_values_all) annotator.annotate() ax.set_ylim(-950, -550) plt.show()`

I tried to use several different hyperparameters, such as line_offset_to_group. The only way to make it works is to put annotations outside. image

I would very appreciate if anyone could guide me. Thank you!

trevismd commented 2 years ago

Hello, @inqlee0704, Thanks for the question.

I'll assume that the plot is OK if shown without annotations.

It seems to be thinking that there is a need to plot data around y=0 for the All group. But somehow there's nothing on the plot. So first, does addingfliersize=0 to your Annotator() call solves your problem? If it's not the case (possible if All is not really the union of all other groups, otherwise it should also happen on another column), could you check what happens when you exclude all the All datapoints from the dataset?

inqlee0704 commented 2 years ago

Adding fliersize=0 didn't solve the issue.

This is what I got after removing 'All' annotations:

image

And this is what I got after deleting 'All' datapoints from the dataset.

image

Yes, it seems that the first group always has this issue.

trevismd commented 2 years ago

Hmmm.... Can you please show seaborn's plot without the annotations and with outliers ? So, only

plt.figure(figsize=(15,8))
sns.boxplot(x=x,y=y, hue=hue,data=df)
plt.show()

Also, do you have the problem with any number of groups (lobes)? We see here with 5 but is it the same with 4, 3, and 2 ? Would you be OK with sharing a minimal dataset that I can use to reproduce and debug locally ?

inqlee0704 commented 2 years ago

Here is the result without annotations and with outliers.

image

Sure, here is the link to the csv file. https://docs.google.com/spreadsheets/d/1bsKKYArRF_Iwag2TMVQ4kQKRX48OxYuECToA2vmveEM/edit#gid=0 Please let me know if the link doesn't work.