In [1]:
drive_path = 'c:/'
import numpy as np
import pandas as pd
import os
import sys
import matplotlib.pyplot as plt
from scipy.stats import ks_2samp
from scipy.stats import anderson_ksamp
from scipy.stats import kruskal
from scipy.stats import variation
%matplotlib
import seaborn as sns
In [17]:
comp=pd.read_csv('C:\Users\Annie\Documents\Data\Ca_Imaging\Analysis\Odor_Panel\Composite_MaxDF_NoP.csv')
del comp['Mouse']
comp_sorted=comp.reindex_axis(comp.mean().sort_values().index, axis=1)
comp_labels=pd.DataFrame(comp.Group)
tmp=[comp_labels,comp_sorted]
composite_full=pd.concat(tmp,axis=1)
composite_full.head()
cfull=pd.melt(composite_full,"Group",var_name="Odor")
In [69]:
MS005_full=composite_full[['Group','MS 0.05']]
MS005df=pd.melt(MS005_full,"Group",var_name="Odor")
cg=MS005_full[MS005_full['Group']=='Control']
mg=MS005_full[MS005_full['Group']=='Mint']
hg=MS005_full[MS005_full['Group']=='Hexanal']
In [19]:
from scipy.stats import gaussian_kde
In [24]:
In [63]:
#Get the peak of the control kde
gkde=gaussian_kde(cg['MS 0.05'])
x=np.arange(-1,5,0.01)
y=gkde.evaluate(x)
max_y_value=np.amax(y)
max_y_index=np.argmax(y)
#use this max x value to shift the entire distribution
max_x_value=x[np.argmax(y)]
In [95]:
#make a dataframe of x,y coordinates of the kde, with a bin size of 0.01
xdf=pd.DataFrame(x)
xdf.columns=['x']
newxdf=pd.DataFrame(xdf['x']-max_x_value)
ydf=pd.DataFrame(y)
ydf.columns=['y']
coordinates=pd.concat([xdf,ydf],axis=1)
newcoordinates=pd.concat([newxdf,ydf],axis=1)
# plot it!
plt.plot(coordinates['x'],coordinates['y'])
plt.plot(newcoordinates['x'],coordinates['y'])
Out[95]:
In [ ]:
In [ ]:
In [ ]:
In [92]:
#Get the peak of the mint kde
mkde=gaussian_kde(mg['MS 0.05'])
mx=np.arange(-1,5,0.01)
my=mkde.evaluate(mx)
m_max_y_value=np.amax(my)
m_max_y_index=np.argmax(my)
#use this max x value to shift the entire distribution
m_max_x_value=mx[np.argmax(my)]
In [93]:
m_max_x_value
Out[93]:
In [94]:
#make a dataframe of x,y coordinates of the kde, with a bin size of 0.01
mxdf=pd.DataFrame(mx)
mxdf.columns=['x']
mnewxdf=pd.DataFrame(mxdf['x']-m_max_x_value)
mydf=pd.DataFrame(my)
mydf.columns=['y']
m_coordinates=pd.concat([mxdf,mydf],axis=1)
m_newcoordinates=pd.concat([mnewxdf,mydf],axis=1)
# plot it!
plt.plot(m_coordinates['x'],m_coordinates['y'])
plt.plot(m_newcoordinates['x'],m_coordinates['y'])
Out[94]:
In [ ]:
In [ ]:
In [ ]:
In [96]:
#Get the peak of the hexanal kde
hkde=gaussian_kde(hg['MS 0.05'])
hx=np.arange(-1,5,0.01)
hy=hkde.evaluate(hx)
h_max_y_value=np.amax(hy)
h_max_y_index=np.argmax(hy)
#use this max x value to shift the entire distribution
h_max_x_value=hx[np.argmax(hy)]
In [97]:
#make a dataframe of x,y coordinates of the kde, with a bin size of 0.01
hxdf=pd.DataFrame(hx)
hxdf.columns=['x']
hnewxdf=pd.DataFrame(hxdf['x']-h_max_x_value)
hydf=pd.DataFrame(hy)
hydf.columns=['y']
h_coordinates=pd.concat([hxdf,hydf],axis=1)
h_newcoordinates=pd.concat([hnewxdf,hydf],axis=1)
# plot it!
plt.plot(h_coordinates['x'],h_coordinates['y'])
plt.plot(h_newcoordinates['x'],h_coordinates['y'])
Out[97]:
In [100]:
plt.plot(newcoordinates['x'],newcoordinates['y']);
plt.plot(m_newcoordinates['x'],m_newcoordinates['y']);
plt.plot(h_newcoordinates['x'],h_newcoordinates['y']);
In [117]:
sns.set(palette="muted", color_codes=True);
sns.set_context("talk", font_scale=3);
plt.figure(figsize=(24, 18));
plt.plot(newcoordinates['x'],newcoordinates['y'],color='r',label='Control');
plt.plot(m_newcoordinates['x'],m_newcoordinates['y'],color='g',label='Mint');
plt.plot(h_newcoordinates['x'],h_newcoordinates['y'],color='b',label='Hexanal');
sns.despine();
plt.legend(loc='upper right');
plt.title('KDEs, peaks centered');
In [ ]: