Skip to content

Instantly share code, notes, and snippets.

View trevismd's full-sized avatar

Florian Charlier trevismd

  • Belgium
View GitHub Profile
@trevismd
trevismd / Statannotations-Tutorial-1-14.py
Last active July 9, 2021 07:01
Instantiate Annotator
# With ... = all parameters passed to seaborn's plotter
annotator = Annotator(ax, pairs, ...)
@trevismd
trevismd / Statannotations-Tutorial-1-14.py
Last active July 5, 2021 08:11
Instantiate Annotator
# With ... = all parameters passed to seaborn's plotter
annotator = Annotator(ax, box_pairs, ...)
from statannotations.Annotator import Annotator
@trevismd
trevismd / Statannotations-Tutorial-1-13.py
Last active July 9, 2021 07:01
Box pairs for plot 1
pairs = [('Robots', 'Flight'), # 'Robots' vs 'Flight'
('Flight', 'Sound'), # 'Flight' vs 'Sound'
('Robots', 'Sound')] # 'Robots' vs 'Sound'
# pvalues with scipy:
stat_results = [
mannwhitneyu(robots, flight, alternative="two-sided"),
mannwhitneyu(flight, sound, alternative="two-sided"),
mannwhitneyu(robots, sound, alternative="two-sided")
]
pvalues = [result.pvalue for result in stat_results]
print("Robots vs Flight: \n", stat_results[0], "\n")
print("Robots: ", normaltest(robots).pvalue)
print("Flight: ", normaltest(flight).pvalue)
print("Sound: ", normaltest(sound).pvalue)
print()
print("Log(robots): ", normaltest(log_robots).pvalue)
print("Log(Flight): ", normaltest(log_flight).pvalue)
print("Log(Sound): ", normaltest(log_sound).pvalue)
@trevismd
trevismd / Statannotations-Tutorial-1-9.py
Created July 4, 2021 18:40
Extracting arrays to analyse with scipy
robots = rfs.loc[(rfs.Subcategory == "Robots"), "Goal"].values
flight = rfs.loc[(rfs.Subcategory == "Flight"), "Goal"].values
sound = rfs.loc[(rfs.Subcategory == "Sound"), "Goal"].values
log_robots = np.log(robots)
log_flight = np.log(flight)
log_sound = np.log(sound)
# [code common to all plots]
# Plot with seaborn
sns.boxplot(ax=ax, data=rfs, x='State', y='Goal', order=states_order,
palette=states_palette)
# [code common to all plots]
with sns.plotting_context("notebook", font_scale=1.4):
# Create new plot, setting a logarithmic scale for y
ax = get_log_ax()
# Plot with seaborn
sns.boxplot(ax=ax, data=rfs, x='Subcategory', y='Goal', palette=subcat_palette[1:])
# Label (adds axes labels and title), and show
label_plot_for_subcats(ax)
plt.savefig("plot1.png")
@trevismd
trevismd / Statannotations-Tutorial-1-6.py
Last active August 3, 2021 07:06
Color and order - Subcategories
subcat_palette = sns.dark_palette("#8BF", reverse=True, n_colors=5)
subcat_order = ['Robots', 'Flight', 'Sound']