I have the following DataFrame on a Jupyter notebook which plots using seaborn a barplot:
data = {'day_index': [0, 1, 2, 3, 4, 5, 6],
'avg_duration': [708.852242, 676.7021900000001, 684.572677, 708.92534, 781.767476, 1626.575057, 1729.155673],
'trips': [114586, 120936, 118882, 117868, 108036, 43740, 37508]}
df = pd.DataFrame(data)
daysOfWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
plt.figure(figsize=(16,10));
sns.set_style('ticks')
ax = sns.barplot(data=df, \
x='day_index', \
y='avg_duration', \
hue='trips', \
palette=sns.color_palette("Reds_d", n_colors=7, desat=1))
ax.set_xlabel("Week Days", fontsize=18, alpha=0.8)
ax.set_ylabel("Duration (seconds)", fontsize=18, alpha=0.8)
ax.set_title("Week's average Trip Duration", fontsize=24)
ax.set_xticklabels(daysOfWeek, fontsize=16)
ax.legend(fontsize=15)
sns.despine()
plt.show()
As it can be seen the bars do not match the x_ticklabels and are very thin.
This is all fixed if I remove the hue='trips'
part, it's a known seaborn issue.
Although It's very important to show the amount of trips in the visualization so: is there a way around seaborn (maybe with matplotlib directly) to add a hue attribute?