0

I started to use python 6 months ago and may be my question is a naive one. I would like to visualize my data and ANOVA statistics. It is common to do this using a barplot with added lines indicating significant differences and interactions. How do you make plot like this using python ?

enter image description here

Here is a simple dataframe, with 3 columns (A,B and the p_values already calculated with a t-test)

mport pandas as pd
import matplotlib.pyplot as plt
import numpy as np

ar = np.array([  [565.0, 81.0, 1.630947e-02], 
                    [1006.0, 311.0, 1.222740e-27], 
                    [2929.0, 1292.0, 5.559912e-12],
                    [3365.0, 1979.0, 2.507474e-22],
                    [2260.0, 1117.0, 1.540305e-01]])
df = pd.DataFrame(ar,columns = ['A', 'B', 'p_value'])

ax = plt.subplot()

# I calculate the percentage
(df.iloc[:,0:2]/df.iloc[:,0:2].sum()*100).plot.bar(ax=ax)

for container, p_val in zip(ax.containers,df['p_value']):
    labels = [f"{round(v,1)}%" if (p_val > 0.05) else f"(**)\n{round(v,1)}%" for v in container.datavalues]
    ax.bar_label(container,labels=labels, fontsize=10,padding=8)

plt.show()

Initially I just wanted to add a "**" each time a significant difference is observed between the 2 columns A & B. But the initial code above is not really working.

Now I would prefer having the added lines indicating significant differences and interactions between the A&B columns. But I have no ideas how to make it happen.

Regards JYK

jyk95
  • 1

0 Answers0