Colorbars change plot dimensions
See original GitHub issueThanks so much for adding colorbars to Bokeh 0.12.2!
If I take the colorbar example from http://bokeh.pydata.org/en/latest/docs/user_guide/annotations.html and comment out the colorbar, I get a nice square plot:
But if I enable the colorbar, it’s all squished:
To me, this is very surprising behavior – why would I want my plot to get squished when I add a colorbar? A colorbar is something outside my plot. It seems to be putting the entire plot into a box and then adjusting the internal plot size, which makes sense for making it easier to lay out the rest of the page, but it’s definitely not what I would have wanted. And I don’t see any obvious way to restore my plot to its rightful dimensions, which would appear to require finding out how big the colorbar is somehow.
The code is below; my only change was to specify the size as 200x200, but the default size has the same issue.
import numpy as np
from matplotlib.mlab import bivariate_normal
from bokeh.plotting import figure, output_file, show
from bokeh.models import LogColorMapper, LogTicker, ColorBar
output_file('color_bar.html')
N = 100
X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)]
Z1 = bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0) + \
0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
image = Z1 * 1e6
color_mapper = LogColorMapper(palette="Viridis256", low=1, high=1e7)
plot = figure(x_range=(0,1), y_range=(0,1), height=200, width=200, toolbar_location=None)
plot.image(image=[image], color_mapper=color_mapper,
dh=[1.0], dw=[1.0], x=[0], y=[0])
color_bar = ColorBar(color_mapper=color_mapper, ticker=LogTicker(),
label_standoff=12, border_line_color=None, location=(0,0))
plot.add_layout(color_bar, 'right')
show(plot)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:10 (8 by maintainers)
Top GitHub Comments
Not a real solution, but at least a workaround that is a bit more pleasant to use than the one from @jbednar because only the
width
of the dummy figure has to be set to a meaningful value. The “trick” is to specify the figure height (and width) and use this height for all figures. Unfortunately one cannot get the height of an existing figure viafigure.height
and use it for the dummy figure. That would be easiest. Alternatively one could get the width of the bounding box of the colorbar, but I have not found out how to get that…Here is my “solution” (a modification of the above on from jbednar, incorporating ideas from this SO answer
By default nothing will change, however, PR #8085 adds support for configuring frame dimensions (instead of plot dimensions), so with some configuration this issue will be solvable.