Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to fix height of colorbar in Matplotlib

📅 2014-Nov-17 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

When a colorbar is used in a Matplotlib plot, it is usually drawn with a height that is larger than the plot itself. Many solutions to this problem are suggested here. The one that worked for me was this:

plt.colorbar(im, fraction=0.046, pad=0.04)

This sets the colorbar height equal to the height of the plot for me.

Tried with: Matplotlib 1.3.1-1, Python 2.7.6 and Ubuntu 14.04