Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

"loc=outside" causes significance annotations to be cut out of the plot #80

Closed
saskra opened this issue Jul 2, 2021 · 4 comments
Closed

Comments

@saskra
Copy link

saskra commented Jul 2, 2021

Example:
violin_out

Code:

sns.set_style('ticks')
ax = sns.violinplot(data=df_jpi, inner=None, color=".8")
sns.stripplot(data=df_jpi)
# ax.set(ylim=(0, 1))
test_results = add_stat_annotation(ax, 
                                                      data=df_jpi, 
                                                      box_pairs=[("X", "Y"), ("X", "Z"), ("Y", "Z")], 
                                                      test='Mann-Whitney', 
                                                      text_format='star', 
                                                      loc='outside', 
                                                      verbose=2)
fig = ax.get_figure()
fig.savefig('violin_out.png', transparent=True)
fig.show()

This does not happen with "loc=inside".

@trevismd
Copy link

trevismd commented Jul 2, 2021

Could you provide a small dataset to explore this ?

@saskra
Copy link
Author

saskra commented Jul 5, 2021

It does not depend on the dataset, so you can just use random data like these:

df_jpi = pd.DataFrame(np.random.randint(0, 100, size=(100, 3)), columns=list('XYZ'))

@trevismd
Copy link

trevismd commented Jul 5, 2021

You can use

fig.tight_layout()

to resize the figure to the added content before calling plt.show().
This is done with the parameter bbox_inches='tight' when saving the image (such as in the example notebook), but for plt.show(), this is the function to call first.

Thanks for reporting this. I'll look into automatically performing this step after adding annotations outside the plotting area (in statannotations).

@saskra
Copy link
Author

saskra commented Jul 5, 2021

Thanks a lot!

@saskra saskra closed this as completed Jul 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants