In [44]:
import pandas
import numpy
%matplotlib inline
from matplotlib import pyplot
from matplotlib.lines import Line2D
import seaborn
from scipy import stats
In [15]:
from matplotlib import rcParams
In [18]:
data_filepath = ""
In [19]:
seaborn_blue = seaborn.color_palette()[0]
seaborn.set()
In [16]:
rcParams['font.sans-serif']
Out[16]:
In [17]:
rcParams['font.sans-serif'] = ['Helvetica Neue',
'Arial',
'Bitstream Vera Sans',
'DejaVu Sans',
'Lucida Grande',
'Verdana',
'Geneva',
'Lucid',
'Avant Garde',
'sans-serif']
In [20]:
data = pandas.read_csv(data_filepath)
data = data.loc[data.site<=30]
In [21]:
data = data.sort_values(by=['site', 'sound']).reset_index(drop=True)
In [24]:
means = data[['site', 'sel', 'biophony']].groupby('site').mean()
mins = data[['site', 'sel', 'biophony']].groupby('site').min()
maxs = data[['site', 'sel', 'biophony']].groupby('site').max()
In [114]:
figure4, ax = pyplot.subplots()
figure4.subplots_adjust(left=0.15, bottom=0.15, right=0.95, top=0.95, wspace=0, hspace=0)
figure4.set_figheight(3.30)
figure4.set_figwidth(3.30)
p1 = ax.scatter('sel', 'biophony', data=means, color='black')
xl = ax.set_xlabel('SEL (decibels)')
yl = ax.set_ylabel('percent biophony')
lx = ax.set_xlim(-60, -30)
ly = ax.set_ylim(0, 15)
yt = ax.set_yticks(numpy.arange(1, 17, 2))
for s in means.index:
x = means.loc[s].sel
y1 = mins.loc[s].biophony
y2 = maxs.loc[s].biophony
ax.add_line(Line2D([x, x], [y1, y2], color='black', linewidth=1, alpha=0.5))
# legend
ap = dict(arrowstyle='-',
connectionstyle='arc3,rad=0.3', linestyle=':', linewidth=0.5, color='gray')
a1 = ax.annotate('site mean', (means.loc[29].sel, means.loc[29].biophony), xytext=(-38, 5), arrowprops=ap)
a2 = ax.annotate('site max', (means.loc[29].sel, maxs.loc[29].biophony), xytext=(-38, 6), arrowprops=ap)
a3 = ax.annotate('site min', (means.loc[29].sel, mins.loc[29].biophony), xytext=(-38, 4), arrowprops=ap)
# pearsonr
r = stats.pearsonr(x=means.sel, y=means.biophony)
a4 = ax.text(x=-31, y=14, s='pearsonr = {0:.2f}, p = {1:.1e}'.format(r[0], r[1]), ha='right', va='center')
In [116]:
#figure4.savefig("", dpi=600)