0

Hello I need help on my project. I am using the codes below to have a heatmap, but I could not put days in order. Seems as below, I want it to start from monday, how can I do that? enter image description here

fig=plt.figure(figsize=(10,10), dpi= 80, edgecolor='k')

#plot1
plt.subplot(2, 1, 1)
subs = df_ford_cleaned.query('user_type == "Subscriber"')
subs_counts = subs.groupby(['start_day', 'start_hour']).size()
subs_counts = subs_counts.reset_index(name='count')
subs_counts = subs_counts.pivot(index='start_day', columns='start_hour', values='count')
sb.heatmap(subs_counts, cmap='rocket_r');
plt.title('Subscriber', loc='left',fontsize=16);
plt.xlabel('Hour of Day',fontsize=12);
plt.ylabel('Days',fontsize=12);

#plot2
plt.subplot(2, 1, 2)
cust = df_ford_cleaned.query('user_type == "Customer"')
cust_counts = cust.groupby(['start_day', 'start_hour']).size()
cust_counts = cust_counts.reset_index(name='count')
cust_counts = cust_counts.pivot(index='start_day', columns='start_hour', values='count')
sb.heatmap(cust_counts, cmap='rocket_r');
plt.title('Customer', loc='left',fontsize=16);
plt.xlabel('Hours',fontsize=12);
plt.ylabel('Days',fontsize=12);

#title
plt.suptitle("Hourly and Daily Usage for Customers and Subscribers", y = 1.04,fontweight='semibold', color = 'Green',)
BigBen
  • 38,994
  • 6
  • 24
  • 37
serdarsen
  • 39
  • 4
  • You can impose an order via `cust_counts = cust_counts.reindex(['Monday','Tuesday',...])`. Another option is to make the original column categorical, which lets you set an order. – JohanC Jan 03 '22 at 22:41

0 Answers0