I've made this boxplot graph
# Tamanho do gráfico em polegadas
plt.figure(figsize=(11, 6))
# Gráfico
ax = sns.boxplot(x="CÓD. ESTAÇÃO", y ="FERRO", data=df_FERRO, linewidth=1.0, color='#5d6b75')
ax.set_ylim(min(df_FERRO['FERRO']) - 0.5, max(df_FERRO['FERRO']) + 0.5)
# Cores
colors = ['#8ECEEA', '#FDF7AD', '#AC5079']
bins = [0.3, 5, 20]
base = -10
for top, c in zip(bins, colors):
ax.axhspan(base, top, color=c, zorder=0)
base = top
# Adicionando Título ao gráfico
plt.title("Ferro dissolvido (2017 - 2022)", loc="center", fontsize=18)
plt.xlabel("Estação")
plt.ylabel("mg/L Fe")
plt.show()
I need to insert a legend for the layers (represented by colors), i may say it's a legend for the "colored boxes". I've got this example (graph made in R) of what I expect:
It doesn't need to be exact like this graph, but it needs to express this idea. I've only found examples for lines, instead of layers.
label=
toax.axhspan(base, top, color=c, zorder=0, label=f'bin={base}-{top}')
. Then these labels together with the colored boxes will appear in the legend, which you can create withplt.legend(loc='upper left', title='legenda')
.