Seaborn heatmap change size of colorbar
I think your problem is in the figure proportions. Instead of declaring...
fig, ax = plt.subplots(figsize=(30,60))
...try keeping the proportions even:
fig, ax = plt.subplots(figsize=(30,30))
That worked for me.
To follow up on DavidG's very useful answer and Yuca's question (apologies, I can't comment):
If you have multiple cbar_kws, it can be useful to supply the cbar_kws via a dictionary constructed from name=value pairs.
E.g. A common cbar_kws dict that I use for seaborn heatmaps:
cbar_kws=dict(use_gridspec=False,location="bottom",pad=0.01,shrink=0.25)
Here, Yuca could do the following to shrink the cbar and change the padding (try a few pad values to see which one looks best): `cbar_kws=dict(shrink=0.5,pad=0.01)
As said in the comments, I cannot reproduce this issue using Seaborn version 0.8 and matplotlib 2.1.1, therefore if possible I would recommend updating the modules.
That being said, you can manipulate the size of the colorbar using the cbar_kws
argument in seaborn.heatmap
. This needs to be a dictionary which is passed (under the hood) as kwargs to matplotlibs fig.colorbar()
.
One kwarg of interest is the shrink
parameter. This shrinks the size of the colorbar:
shrink: 1.0; fraction by which to multiply the size of the colorbar
The default should be 1.0, so you could try manually setting this to 1. However, if this does not work you can shrink the colorbar more by using a lower value. This may require some tinkering in order to get the colorbar the right size.
fig, ax = plt.subplots()
cmap = plt.get_cmap('inferno',30)
cmap.set_under('white')#Colour values less than vmin in white
cmap.set_over('yellow')# colour valued larger than vmax in red
Crosstab=50000*np.random.randn(10,10)
heatmap=sns.heatmap(Crosstab[::-1],cmap=cmap,annot=False,square=True,ax=ax,vmin=1,vmax=50000,
cbar_kws={"shrink": 0.5},linewidths=0.8,linecolor="grey")
plt.show()
Giving: