diff --git a/scripts/daily_plot.py b/scripts/daily_plot.py index 5674ab1..2240314 100755 --- a/scripts/daily_plot.py +++ b/scripts/daily_plot.py @@ -57,12 +57,28 @@ df_plt_top10_today = df_plt_today[df_plt_today.Com_Name.isin(plt_top10_today.ind pal = "Greens" #Set up plot axes and titles -f, axs = plt.subplots(1, 3, figsize = (10, 4), gridspec_kw=dict(width_ratios=[3, 2, 5])) +# f, axs = plt.subplots(1, 3, figsize = (10, 4), gridspec_kw=dict(width_ratios=[3, 2, 5])) + +f, axs = plt.subplots(1, 2, figsize = (10, 4), gridspec_kw=dict(width_ratios=[3, 6])) plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0, hspace=0) +#generate y-axis order for all figures based on frequency +freq_order = pd.value_counts(df_plt_top10_today['Com_Name']).iloc[:readings].index + +#make color for max confidence --> this groups by name and calculates max conf +confmax = df_plt_top10_today.groupby('Com_Name')['Confidence'].max() +#reorder confmax to detection frequency order +confmax = confmax.reindex(freq_order) + +# norm values for color palette +norm = plt.Normalize(confmax.values.min(), confmax.values.max()) +colors = plt.cm.Greens(norm(confmax)) #Generate frequency plot -plot=sns.countplot(y='Com_Name', data = df_plt_top10_today, palette = pal+"_r", order=pd.value_counts(df_plt_top10_today['Com_Name']).iloc[:readings].index, ax=axs[0]) +plot=sns.countplot(y='Com_Name', data = df_plt_top10_today, palette = colors, order=freq_order, ax=axs[0]) + + + #Try plot grid lines between bars - problem at the moment plots grid lines on bars - want between bars # plot.grid(True, axis='y') @@ -71,16 +87,16 @@ plot.set_yticklabels(['\n'.join(textwrap.wrap(ticklabel.get_text(),15)) for tick plot.set(ylabel=None) plot.set(xlabel="Detections") -huw=df_plt_top10_today.groupby('Com_Name')['Confidence'].mean() -plot = sns.boxenplot(x=df_plt_top10_today['Confidence']*100,color='Green', y=df_plt_top10_today['Com_Name'], ax=axs[1],order=pd.value_counts(df_plt_top10_today['Com_Name']).iloc[:readings].index) -plot.set(xlabel="Confidence", ylabel=None,yticklabels=[]) +# huw=df_plt_top10_today.groupby('Com_Name')['Confidence'].mean() +# plot = sns.boxenplot(x=df_plt_top10_today['Confidence']*100,color='Green', y=df_plt_top10_today['Com_Name'], ax=axs[1],order=freq_order) +# plot.set(xlabel="Confidence", ylabel=None,yticklabels=[]) #Generate crosstab matrix for heatmap plot heat = pd.crosstab(df_plt_top10_today['Com_Name'],df_plt_top10_today['Hour of Day']) #Order heatmap Birds by frequency of occurrance -heat.index = pd.CategoricalIndex(heat.index, categories = pd.value_counts(df_plt_top10_today['Com_Name']).iloc[:readings].index) +heat.index = pd.CategoricalIndex(heat.index, categories = freq_order) heat.sort_index(level=0, inplace=True) @@ -89,7 +105,8 @@ heat_frame = pd.DataFrame(data=0, index=heat.index, columns = hours_in_day) heat=(heat+heat_frame).fillna(0) #Generatie heatmap plot -plot = sns.heatmap(heat, norm=LogNorm(), annot=True, fmt="g", annot_kws={"fontsize":7}, cmap = pal , square = False, cbar=False, linewidths = 0.5, linecolor = "Grey", ax=axs[2], yticklabels = False) +plot = sns.heatmap(heat, norm=LogNorm(), annot=True, annot_kws={"fontsize":7}, cmap = pal , square = False, cbar=False, linewidths = 0.5, linecolor = "Grey", ax=axs[1], yticklabels = False) +plot.set_xticklabels(plot.get_xticklabels(), rotation = 0, size = 7) # Set heatmap border for _, spine in plot.spines.items(): @@ -100,28 +117,44 @@ plot.set(xlabel="Hour of Day") #Set combined plot layout and titles # plt.tight_layout() f.subplots_adjust(top=0.9) -plt.suptitle("Last Updated: "+ str(now.strftime("%d %m %Y %H:%M"))) +plt.suptitle("Last Updated: "+ str(now.strftime("%d-%m-%Y %H:%M"))) #Save combined plot savename='/home/pi/BirdSongs/Extracted/Charts/Combo-'+str(now.strftime("%d-%m-%Y"))+'.png' plt.savefig(savename) -# plt.show() +#plt.show() plt.close() -#Get bottom 10 today -plt_bot10_today = (df_plt_today['Com_Name'].value_counts()[-readings:]) -df_plt_bot10_today = df_plt_today[df_plt_today.Com_Name.isin(plt_bot10_today.index)] + +# Get Bottom detection frequency +plt_Bot10_today = (df_plt_today['Com_Name'].value_counts()[-readings:]) +df_plt_Bot10_today = df_plt_today[df_plt_today.Com_Name.isin(plt_Bot10_today.index)] #Set Palette for graphics pal = "Reds" #Set up plot axes and titles -f, axs = plt.subplots(1, 3, figsize = (10, 4), gridspec_kw=dict(width_ratios=[3, 2, 5])) +# f, axs = plt.subplots(1, 3, figsize = (10, 4), gridspec_kw=dict(width_ratios=[3, 2, 5])) + +f, axs = plt.subplots(1, 2, figsize = (10, 4), gridspec_kw=dict(width_ratios=[3, 6])) plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0, hspace=0) +#generate y-axis order for all figures based on frequency +freq_order = pd.value_counts(df_plt_Bot10_today['Com_Name']).iloc[-readings:].index + +#make color for max confidence --> this groups by name and calculates max conf +confmax = df_plt_Bot10_today.groupby('Com_Name')['Confidence'].max() +confmax = confmax.reindex(freq_order) +# probably wrong order . . . how to sort by no. of detections ? +# norm values for color palette +norm = plt.Normalize(confmax.values.min(), confmax.values.max()) +colors = plt.cm.Reds(norm(confmax)) #Generate frequency plot -plot=sns.countplot(y='Com_Name', data = df_plt_bot10_today, palette = pal+"_r", order=pd.value_counts(df_plt_bot10_today['Com_Name']).iloc[-readings:].index, ax=axs[0]) +plot=sns.countplot(y='Com_Name', data = df_plt_Bot10_today, palette = colors, order=freq_order, ax=axs[0]) + + + #Try plot grid lines between bars - problem at the moment plots grid lines on bars - want between bars # plot.grid(True, axis='y') @@ -130,16 +163,16 @@ plot.set_yticklabels(['\n'.join(textwrap.wrap(ticklabel.get_text(),15)) for tick plot.set(ylabel=None) plot.set(xlabel="Detections") -huw=df_plt_bot10_today.groupby('Com_Name')['Confidence'].mean() -plot = sns.boxenplot(x=df_plt_bot10_today['Confidence']*100,color='Red', y=df_plt_bot10_today['Com_Name'], ax=axs[1],order=pd.value_counts(df_plt_bot10_today['Com_Name']).iloc[-readings:].index) -plot.set(xlabel="Confidence", ylabel=None,yticklabels=[]) +# huw=df_plt_Bot10_today.groupby('Com_Name')['Confidence'].mean() +# plot = sns.boxenplot(x=df_plt_Bot10_today['Confidence']*100,color='Green', y=df_plt_Bot10_today['Com_Name'], ax=axs[1],order=freq_order) +# plot.set(xlabel="Confidence", ylabel=None,yticklabels=[]) #Generate crosstab matrix for heatmap plot -heat = pd.crosstab(df_plt_bot10_today['Com_Name'],df_plt_bot10_today['Hour of Day']) +heat = pd.crosstab(df_plt_Bot10_today['Com_Name'],df_plt_Bot10_today['Hour of Day']) #Order heatmap Birds by frequency of occurrance -heat.index = pd.CategoricalIndex(heat.index, categories = pd.value_counts(df_plt_bot10_today['Com_Name']).iloc[-readings:].index) +heat.index = pd.CategoricalIndex(heat.index, categories = freq_order) heat.sort_index(level=0, inplace=True) @@ -148,7 +181,8 @@ heat_frame = pd.DataFrame(data=0, index=heat.index, columns = hours_in_day) heat=(heat+heat_frame).fillna(0) #Generatie heatmap plot -plot = sns.heatmap(heat, norm=LogNorm(), annot=True, annot_kws={"fontsize":7}, cmap = pal , square = False, cbar=False, linewidths = 0.5, linecolor = "Grey", ax=axs[2], yticklabels = False) +plot = sns.heatmap(heat, norm=LogNorm(), annot=True, annot_kws={"fontsize":7}, cmap = pal , square = False, cbar=False, linewidths = 0.5, linecolor = "Grey", ax=axs[1], yticklabels = False) +plot.set_xticklabels(plot.get_xticklabels(), rotation = 0, size = 7) # Set heatmap border for _, spine in plot.spines.items(): @@ -159,10 +193,10 @@ plot.set(xlabel="Hour of Day") #Set combined plot layout and titles # plt.tight_layout() f.subplots_adjust(top=0.9) -plt.suptitle("Last Updated: "+ str(now.strftime("%d %m %Y %H:%M"))) +plt.suptitle("Last Updated: "+ str(now.strftime("%d-%m-%Y %H:%M"))) #Save combined plot savename='/home/pi/BirdSongs/Extracted/Charts/Combo2-'+str(now.strftime("%d-%m-%Y"))+'.png' plt.savefig(savename) -#plt.show() +# plt.show() plt.close()