Created
September 7, 2020 16:12
-
-
Save tanpengshi/31332576febb09a6b7713301928cfcc6 to your computer and use it in GitHub Desktop.
Creating Heatmap Matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
matrix_list= [] | |
for station in list(group_station.head(10).index): | |
df_station = df_10[df_10['STATION']==station] | |
group_day_time = df_station.groupby(['WEEKDAY','TIME_PERIOD'])['ENTRY_EXIT'].sum() | |
matrix_day_time = group_day_time.unstack() | |
matrix_day_time.reset_index() | |
matrix_day_time = matrix_day_time.reindex(index=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]) | |
matrix_day_time = matrix_day_time.reindex(columns=["12am-4am","4am-8am","8am-12pm","12pm-4pm","4pm-8pm","8pm-12am"]) | |
matrix_list.append(matrix_day_time) | |
fig, axn = plt.subplots(2,5, sharex=True, sharey=True, figsize=(15,6)) | |
cmap = sns.cubehelix_palette(light=1, as_cmap=True) | |
cbar_ax = fig.add_axes([.91, .3, .03, .4]) | |
for i, ax in enumerate(axn.flat): | |
station = matrix_list[i] | |
sns.heatmap(station, ax=ax, cmap=cmap, | |
cbar=i == 0, | |
cbar_ax=None if i else cbar_ax, | |
linecolor='white',linewidths=0.5) | |
ax.set_title(list(group_station.head(10).index)[i]) | |
ax.set_xlabel('') | |
ax.set_ylabel('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment