daily_plot: use sci name for grouping

This commit is contained in:
frederik
2025-09-28 20:00:13 +02:00
parent b357a43228
commit 5029a417c2
+11 -9
View File
@@ -69,14 +69,14 @@ def create_plot(df_plt_today, now, is_top=None):
if is_top is not None: if is_top is not None:
readings = 10 readings = 10
if is_top: 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: else:
plt_selection_today = (df_plt_today['Com_Name'].value_counts()[-readings:]) plt_selection_today = (df_plt_today['Sci_Name'].value_counts()[-readings:])
else: else:
plt_selection_today = df_plt_today['Com_Name'].value_counts() plt_selection_today = df_plt_today['Sci_Name'].value_counts()
readings = len(df_plt_today['Com_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() 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) 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 # 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 # 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 # reorder confmax to detection frequency order
confmax = confmax.reindex(freq_order) confmax = confmax.reindex(freq_order)
@@ -120,14 +120,16 @@ def create_plot(df_plt_today, now, is_top=None):
name = "Combo2" name = "Combo2"
# Generate frequency plot # 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') palette=dict(zip(confmax.index, colors)), order=freq_order, ax=axs[0], edgecolor='lightgrey')
# Prints Max Confidence on bars # Prints Max Confidence on bars
show_values_on_bars(axs[0], confmax) 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 # 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 # Next two lines avoid a UserWarning on set_ticklabels() requesting a fixed number of ticks
yticks = plot.get_yticks() yticks = plot.get_yticks()
plot.set_yticks(yticks) plot.set_yticks(yticks)