I am trying to put the indices on the Y-axis from 0 to 80k and make it go 10 to 10 however I don’t know why all the indices all overlap at the same point however the legend is displayed fine even using the same function. Also I wanted to know how to change the color of the columns from light green and make it darker as the value increases because the low values are too light and don’t show well
dept_sales = train_plt[['Dept', 'Weekly_Sales']]
# Raggruppa per dipartimento
grouped_sales = dept_sales.groupby('Dept').agg({'Weekly_Sales':'sum'}).reset_index()
# Ordina i dati per dipartimento
grouped_sales = grouped_sales.sort_values('Dept')
# Crea una mappa di colori basata sulle vendite settimanali
colors = plt.cm.Greens(np.linspace(0.3, 1, len(grouped_sales)))
color_map = plt.cm.ScalarMappable(cmap=plt.cm.Greens, norm=plt.Normalize(vmin=grouped_sales['Weekly_Sales'].min(), vmax=grouped_sales['Weekly_Sales'].max()))
# Crea il plot
fig, ax = plt.subplots(figsize=(10,6))
bars = ax.bar(grouped_sales['Dept'], grouped_sales['Weekly_Sales'], color=color_map.to_rgba(grouped_sales['Weekly_Sales']))
ax.set_title('Vendite settimanali per dipartimento')
ax.set_xlabel('Dipartimento')
ax.set_ylabel('Vendite settimanali')
# Imposta i valori sull'asse y
yticks = np.arange(0, 80e3+1, 10e3)
ax.set_yticks(yticks)
ax.set_yticklabels(['{:.0f}k'.format(ytick/1e3) for ytick in yticks])
# Crea una barra dei colori come legenda
sm = plt.cm.ScalarMappable(cmap=plt.cm.Greens, norm=plt.Normalize(vmin=0, vmax=80e3))
cbar = plt.colorbar(sm, ax=ax)
cbar.set_label('Vendite settimanali', rotation=270, labelpad=20)
# Imposta i valori sulla barra dei colori
cbar.set_ticks(yticks)
cbar.set_ticklabels(['{:.0f}k'.format(ytick/1e3) for ytick in yticks])
plt.show()