From d48e841b76f351cb4efa9c9c8184f77fae898458 Mon Sep 17 00:00:00 2001
From: Jonas Birke <jonas.birke@tum.de>
Date: Tue, 28 Sep 2021 12:43:02 +0200
Subject: [PATCH] Color bar fixed to align with the height of the heatmaps

---
 Wrap/Python/ba_plot.py | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/Wrap/Python/ba_plot.py b/Wrap/Python/ba_plot.py
index 3c7f4667641..6bd2b150188 100644
--- a/Wrap/Python/ba_plot.py
+++ b/Wrap/Python/ba_plot.py
@@ -18,6 +18,9 @@ try:  # workaround for build servers
     import numpy as np
     import matplotlib as mpl
     from matplotlib import pyplot as plt
+    from matplotlib import gridspec, colors
+    from mpl_toolkits.axes_grid1 import make_axes_locatable, axes_size
+
 except Exception as e:
     print("In ba_plot.py: {:s}".format(str(e)))
 
@@ -108,22 +111,29 @@ def plot_array(array, axes_limits=None, **kwargs):
     cmap = kwargs.pop('cmap', CMAP)
     withCBar = kwargs.pop('with_cb', True)
 
-    im = plt.imshow(array,
+    ax = plt.gca()
+    im = ax.imshow(array,
                     cmap=cmap,
                     norm=norm,
                     aspect=aspect,
                     extent=axes_limits,
                     **kwargs)
-    if withCBar:
-        cb = plt.colorbar(im, pad=0.025)
 
     if xlabel:
         plt.xlabel(xlabel, fontsize=label_fontsize)
     if ylabel:
         plt.ylabel(ylabel, fontsize=label_fontsize)
+    if withCBar:
+        aspect = 20
+        pad_fraction = 3 
+
+        divider = make_axes_locatable(ax)
+        width = axes_size.AxesY(ax, aspect=1./aspect)
+        pad = axes_size.Fraction(pad_fraction, width)
+        cax = divider.append_axes("right", size=width, pad=pad)
+        cb = plt.colorbar(im, cax=cax)
     if zlabel:
         cb.set_label(zlabel, size=label_fontsize)
-
     if title:
         plt.title(title)
 
-- 
GitLab