Moving title above the colorbar in Seaborn heatmap

Viewed 5976

I have made a heatmap in Seaborn, and I have a corresponding horizontal colorbar. I've added a title to the colorbar, however, the title appears below the colorbar when I actually want it above. Is there some why I can change this? And is it possible to change the font size of the title and the size of the labels on the colorbar?

fig, ax = plt.subplots(figsize=(30,12))
graph = sns.heatmap(df_pivot, cmap="Blues", linecolor="white", linewidths=0.1, 
            cbar_kws={"orientation": "horizontal", "shrink":0.40, "aspect":40, "label": "Number of accidents"})


ax.set_title("Number of traffic accidents per day & hour combination", 
fontsize=30, fontweight="bold")

from matplotlib import rcParams
rcParams['axes.titlepad'] = 70 # Space between the title and graph

locs, labels = plt.yticks() # Rotating row labels
plt.setp(labels, rotation=0) # Rotating row labels

ax.xaxis.tick_top() # x axis on top
ax.xaxis.set_label_position('top')

graph.tick_params(axis='both',labelsize=15) # Tick label size
graph

This is what it looks like so far. I want the "Number of accidents" title to be ABOVE the colorbar, but BELOW the heatmap. and I want the colorbar to be as wide as the heatmap.

enter image description here

1 Answers
Related