I am trying to plot using seaborn boxplot, however I get the
UnboundLocalError: local variable ‘boxprops’ referenced before assignment. These codes were executing fine last week. I have tried updating seaborn and pyfolio, yet get the same error. Does anyone know how to fix this?
Create a figure with subplots
fig, axes = plt.subplots(nrows=1, ncols=5, figsize=(25, 6), sharey=True)
for ax, model in zip(axes, modelslikebrain):
# Step 1: Filter rows for model
filtered_df = df[df['model'] == model].copy()
# Ensure the stateduration column contains mean values of lists or arrays
filtered_df['stateduration'] = filtered_df['stateduration'].apply(convert_to_mean)
# Step 2: Group by 'layer' and calculate the distribution of 'amountpeaks'
grouped = filtered_df.groupby('layer')['stateduration']
# Create a vertical boxplot using seaborn
sns.boxplot(x='layer', y='stateduration', hue='layer', data = filtered_df, palette = 'Set2', ax=ax)
ax.set_xlabel('Layer')
ax.set_ylabel('State Duration')
ax.set_title(f'{model}')
ax.get_legend().remove()
Set the main title and adjust layout
fig.suptitle(‘Distribution of State Duration per Layer in Various Models’, fontsize=16)
plt.tight_layout(rect=[0, 0, 1, 0.96]) # Adjust layout to make room for the main title
plt.show()
Rhea Groenenberg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.