2016-04-12 2 views
14

Das scheint eine triviale Frage, aber ich habe eine Weile gesucht und kann keine Antwort finden. Es scheint auch etwas zu sein, das ein Standardteil dieser Pakete sein sollte. Weiß jemand, ob es eine standardmäßige Möglichkeit gibt, statistische Annotationen zwischen Verteilungsdiagrammen in Seabohnen aufzunehmen?Wie fügt man statistische Annotationen (Sterne oder p-Werte) in Matplotlib/Seaborn Plots ein?

Zum Beispiel zwischen zwei Box oder Swarmplots?

Example: the yellow distribution is significantly different than the others (by wilcoxon - how can i display that visually?

+1

Sie müssen die zugrunde liegenden matplotlib Achsen ziehen Objekt und Verwendung Axes.text oder Axes.annotate –

+0

Haben Sie zufällig ein R-Beispiel, mit dem Sie vergleichen können? (MVCE! Geben Sie uns einen gemeinsamen Datensatz mit Code und eine Erklärung, was Sie bekommen wollten.) – cphlewis

+0

Ein gutes Beispiel dafür, was ich glaube https://github.com/jbmouret/matplotlib_for_papers – thescoop

Antwort

18

Hier wie statistische Anmerkung zu einem Seaborn Boxdiagramm hinzuzufügen:

import seaborn as sns, matplotlib.pyplot as plt 

tips = sns.load_dataset("tips") 
sns.boxplot(x="day", y="total_bill", data=tips, palette="PRGn") 

# statistical annotation 
x1, x2 = 2, 3 # columns 'Sat' and 'Sun' (first column: 0, see plt.xticks()) 
y, h, col = tips['total_bill'].max() + 2, 2, 'k' 
plt.plot([x1, x1, x2, x2], [y, y+h, y+h, y], lw=1.5, c=col) 
plt.text((x1+x2)*.5, y+h, "ns", ha='center', va='bottom', color=col) 

plt.show() 

Und hier das Ergebnis: box plot annotated

Verwandte Themen