# Source:
# https://stackoverflow.com/questions/33379261/how-can-i-have-a-bar-next-to-python-seaborn-heatmap-which-shows-the-summation-of
fig = plt.figure(figsize=(16,12))
ax1 = plt.subplot2grid((14,10), (0,0), rowspan=12, colspan=7)
ax2 = plt.subplot2grid((14,10), (0,8), rowspan=12, colspan=1)
ax3 = plt.subplot2grid((14,10), (13,0), rowspan=1, colspan=7)
table_pivot= data.pivot_table("Hour",
["DISTRICT"],
columns="DAY_OF_WEEK",
aggfunc = "count")
column_order = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
table_pivot2 = table_pivot.reindex(column_order, axis=1)
table_pivot2 = table_pivot2.drop("External", axis=0)
cmap = sns.cm.rocket_r
sns.heatmap(table_pivot2,
ax=ax1,
annot = True,
fmt="0.1f",
linewidths=.8,
vmin=-0.05,
cmap = cmap,
cbar = False).set_title('Number of Crimes per District and Day of Week',
fontsize=14,
fontweight='bold')
y_axis_labels=['A1','A15','A7','B2','B3','C11','C6','D14','D4','D13','E8','E5']
ax1.xaxis.tick_bottom()
ax1.set_xticklabels(table_pivot2.columns,rotation=40)
ax1.yaxis.tick_right()
ax1.set_yticklabels(y_axis_labels, rotation='horizontal')
sns.heatmap((pd.DataFrame(table_pivot2.sum(axis=0))).transpose(),
ax=ax3,
annot=True,
fmt='g',
cmap=cmap,
cbar=False,
xticklabels=False,
yticklabels=False).set(xlabel='', ylabel='Totals')
sns.heatmap(pd.DataFrame(table_pivot2.sum(axis=1)),
ax=ax2,
annot=True,
fmt='g',
cmap=cmap,
cbar=False,
xticklabels=False,
yticklabels=False).set(xlabel='', ylabel='', title='Totals');
Another heatmap here (no. of crimes per district/hours):