Set the width of the colorbar


Is it possible to fix the width of a colorbar? I have a subplot with heatmaps and Iโ€™d like to make sure every heatmap has the same size (that I need to define). I can easily do it without colorbar:

    def _get_fig_size(self, cell_width, n_rows, n_cols):
        if cell_width is None:
            cell_width = 800 / n_cols
        im_height, im_width = self.img_shape
        ratio = im_height / im_width
        cell_height = ratio * cell_width
        return n_cols * cell_width + 100, n_rows * cell_height

    def plot(self):
        # ...
        width, height = self._get_fig_size(cell_width, n_rows, n_cols)

            margin=dict(t=20, l=20, b=20, r=20),

But when I show the colorbar, the width becomes incorrect. I donโ€™t know how to fix the width of the colorbar or to measure it so that I can adapt the width.



The colorbar attributes are listed here: thickness gives the colorbar width. From my point of view thickness in pixels can be well tuned.

Thanks for the quick answer!