daily_plot: use sci name for grouping
This commit is contained in:
+11
-9
@@ -69,14 +69,14 @@ def create_plot(df_plt_today, now, is_top=None):
|
||||
if is_top is not None:
|
||||
readings = 10
|
||||
if is_top:
|
||||
plt_selection_today = (df_plt_today['Com_Name'].value_counts()[:readings])
|
||||
plt_selection_today = (df_plt_today['Sci_Name'].value_counts()[:readings])
|
||||
else:
|
||||
plt_selection_today = (df_plt_today['Com_Name'].value_counts()[-readings:])
|
||||
plt_selection_today = (df_plt_today['Sci_Name'].value_counts()[-readings:])
|
||||
else:
|
||||
plt_selection_today = df_plt_today['Com_Name'].value_counts()
|
||||
readings = len(df_plt_today['Com_Name'].value_counts())
|
||||
plt_selection_today = df_plt_today['Sci_Name'].value_counts()
|
||||
readings = len(df_plt_today['Sci_Name'].value_counts())
|
||||
|
||||
df_plt_selection_today = df_plt_today[df_plt_today.Com_Name.isin(plt_selection_today.index)]
|
||||
df_plt_selection_today = df_plt_today[df_plt_today.Sci_Name.isin(plt_selection_today.index)]
|
||||
|
||||
conf = get_settings()
|
||||
|
||||
@@ -90,10 +90,10 @@ def create_plot(df_plt_today, now, is_top=None):
|
||||
f, axs = plt.subplots(1, 2, figsize=(10, height), gridspec_kw=dict(width_ratios=[3, 6]), facecolor=facecolor)
|
||||
|
||||
# generate y-axis order for all figures based on frequency
|
||||
freq_order = df_plt_selection_today['Com_Name'].value_counts().index
|
||||
freq_order = df_plt_selection_today['Sci_Name'].value_counts().index
|
||||
|
||||
# make color for max confidence --> this groups by name and calculates max conf
|
||||
confmax = df_plt_selection_today.groupby('Com_Name')['Confidence'].max()
|
||||
confmax = df_plt_selection_today.groupby('Sci_Name')['Confidence'].max()
|
||||
# reorder confmax to detection frequency order
|
||||
confmax = confmax.reindex(freq_order)
|
||||
|
||||
@@ -120,14 +120,16 @@ def create_plot(df_plt_today, now, is_top=None):
|
||||
name = "Combo2"
|
||||
|
||||
# Generate frequency plot
|
||||
plot = sns.countplot(y='Com_Name', hue='Com_Name', legend=False, data=df_plt_selection_today,
|
||||
plot = sns.countplot(y='Sci_Name', hue='Sci_Name', legend=False, data=df_plt_selection_today,
|
||||
palette=dict(zip(confmax.index, colors)), order=freq_order, ax=axs[0], edgecolor='lightgrey')
|
||||
|
||||
# Prints Max Confidence on bars
|
||||
show_values_on_bars(axs[0], confmax)
|
||||
|
||||
# Try plot grid lines between bars - problem at the moment plots grid lines on bars - want between bars
|
||||
yticklabels = ['\n'.join(textwrap.wrap(ticklabel.get_text(), wrap_width(ticklabel.get_text()))) for ticklabel in plot.get_yticklabels()]
|
||||
names_key = df_plt_today.sort_values('Time', ascending=False).groupby('Sci_Name').first()['Com_Name']
|
||||
common_names = [names_key[tick_label.get_text()] for tick_label in plot.get_yticklabels()]
|
||||
yticklabels = ['\n'.join(textwrap.wrap(ticklabel, wrap_width(ticklabel))) for ticklabel in common_names]
|
||||
# Next two lines avoid a UserWarning on set_ticklabels() requesting a fixed number of ticks
|
||||
yticks = plot.get_yticks()
|
||||
plot.set_yticks(yticks)
|
||||
|
||||
Reference in New Issue
Block a user