How to adjust automatic scaling on y-axis when using rect glyph

I have tried to use the rect glyph to make bar plot where the x-axis is Factorrange and the y-axis is normal DataRange1d. It works OK except I observe a lot of padding below the bars. On the screenshot I have a comparison of vbar (top) and rect using the same data. Both got range_padding of 0.1 and range_padding_unit of % and automatic scaling. Adjusting the value of range_padding does not help since it seems the padding is offset from the center of the highest bar.

It is possible to have the same kind of range padding as vbar and keeping the automatic scaling? Or is there a something I need to specify for the rectglyph that I am missing?

I use bokeh ver 2.2.3, python 3.8.1

from import output_file, show, save
from bokeh.plotting import figure
from bokeh.layouts import column


fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
counts = [5, 3, 4, 2, 4, 6]
count_mid = [item*0.5 for item in counts]

def fig(title):
	p = figure(
		x_range = fruits,
		plot_height = 250,
		title = title,
		toolbar_location = None,
		tools = ""
	p.xgrid.grid_line_color = None

	return p

def rng_info(rng):

p1 = fig("Fruit Counts - vbar glyph")
p1.vbar(x = fruits, top = counts, width = 0.9)


p2 = fig("Fruit Counts - rect glyph")
p2.rect(x = fruits, y = count_mid, width = 0.9,	height = counts)


save(column(p1, p2))

The reason for this behavior of Rect glyph, is that it uses “sloppy” bounds (centers +/- max width/height halved) to compute padding (among other things). This seems to be an obvious bug, perhaps a failed attempt to optimize performance.

1 Like

No I think it’s just from well before the real spatial indexing was added. I guess it’s never been updated. Alternatively if rects still support screen dimensions (I don’t think so?) then it is to avoid an expensive complete re-index (in data space) on every range change.

@Jonas_Grave_Kristens please file an issue on GitHub


1 Like