Set the width of the colorbar

Hi!

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)

        fig.update_layout(
            margin=dict(t=20, l=20, b=20, r=20),
            width=width,
            height=height,
            autosize=False,
            plot_bgcolor="white",
        )

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.

Thanks.

@Vayel

The colorbar attributes are listed here: https://plot.ly/python/reference/#heatmap-colorbar. thickness gives the colorbar width. From my point of view thickness in pixels can be well tuned.

Thanks for the quick answer!

three reasons why you should buy plotly pro: support open source, get great support, host your plots and dashboards online