Change colorbar visible attribute without resizing the plot

Now If I have a figure with a colorbar and set the visible attribute of the colorbar to False, the figure stretches to fill the space taken by the colorbar.
Is it possible to keep the figure dimensions fixed when the colorbar visible attribute changes?

1 Like

alternatively is there a way to calculate the colorbar width? I could use it to update the plot width when the colorbar is made invisible

There’s no exact way to know these dimensions from Python since the actual layout only occurs in the browser, and can be subtly affected by available fonts, different browsers, etc. You can guesstimate the width and then set e.g. plot.min_border_right to be some value larger than that, to make sure the space reserved on the side of the plot where you put the colorbar is always at least a minimum amount.

1 Like