My colorbar is very far away from the bottom of my heatmap. Is there a way to move it closer?
My code is:
import seaborn as sns
Granger2 = Granger
Granger2.columns = Granger_colnames
Granger2.index = Granger_rownames
fig, ax = plt.subplots(figsize=(6,25))
sns.heatmap(Granger2, cmap=rvb, cbar=True, ax=ax,linewidths=.5,cbar_kws={"orientation": "horizontal"})
ax.xaxis.tick_top() # x axis on top
ax.xaxis.set_label_position('top')
#Remove ticks
ax.tick_params(axis='both', which='both', length=0)
# Drawing the frame
ax.axhline(y = 0, color='k',linewidth = 1)
ax.axhline(y = Granger2.shape[0], color = 'k',linewidth = 1)
ax.axvline(x = 0, color = 'k', linewidth = 1)
ax.axvline(x = Granger2.shape[1], color = 'k', linewidth = 1)
plt.show()
CodePudding user response:
You can use e.g. cbar_kws={"orientation": "horizontal", "pad":0.02}
. The padding is a fraction of the subplot height, so 0.02 is 2%. See the