-1

I have 2 vbar charts stacked on each other using "column" layout in bokeh. These 2 vbar charts share the same x-axis, and x,y ranges.

TOOLTIPS_1=[("Name","@Names"), ("Total Balance","@weekly{($ 0.00 a)}")]
p1 = figure(x_range=names, plot_width=1000, plot_height=250, title="Purchases in Past 7 Days", tools="pan,wheel_zoom, reset", tooltips=TOOLTIPS_1, sizing_mode = "fixed")
p1.vbar(x='Names', top='weekly', width=1, source=source, line_color="white", color = Spectral5[0])
# x-axis for p1 is set off
p1.xaxis.visible = False
p1.yaxis[0].formatter = NumeralTickFormatter(format="$0.00a")
#set p1 vertical range
max_range = merge.monthly.max()
p1.y_range = Range1d(0, max_range+1000000)

TOOLTIPS_2=[("Name","@Names"), ("Total Balance","@monthly{($ 0.00 a)}")]
p2 = figure(x_range=p1.x_range, y_range = p1.y_range, plot_width=1000, plot_height=250, title="Purchases in Past 30 Days", tools="pan,wheel_zoom, reset", tooltips=TOOLTIPS_2, sizing_mode = "fixed")
p2.vbar(x='Names', top='monthly', width=1, source=source, line_color="white", color = Spectral5[1])
# p2 has a x-axis and it's the same as p1's, although p1's x-axis is turned off
p2.xaxis.major_label_orientation = 1.2
p2.yaxis[0].formatter = NumeralTickFormatter(format="$0.00a")

layout = column(p1,p2)
show(layout)

Although, both p1 and p2 have the same ranges and plot width/height, we have different bar charts(p1's bar chart is larger), because one has axis label and another doesn't. Now, how do I set p1, p2's bar chart the same size?

chen
  • 97
  • 1
  • 10

1 Answers1

1

As of Bokeh 1.1 there is no direct way to specify the size of the inner plot frame directly, only the overall outer canvas size. However, you can specify e.g. min_border_bottom to ensure that the space below the plot frame (the space usually occupied by axes ticks and labels) is always at least a certain minimum size:

p = figure(min_border_bottom=80, ...)

So you can either:

  • pass the the same suitable min_border_bottom to both plots, to make sure that they both plots always reserve the same amount of space below the plot frame (whether there is an axis or not).

  • pass a suitable min_border_bottom to the plot with the axis, and subtract this same value from plot_height of the plot without the axis.

bigreddot
  • 33,642
  • 5
  • 69
  • 122
  • Is there a way that I can create a separate object that contains x-axis information and append this object at the bottom of the charts. I'm getting this idea because in heat-maps, there's normally a ColorBar added on the side as reference, I wonder if there's a similar thing but instead of color, I'll have text in it. – chen Apr 30 '19 at 20:20
  • You could make another plot, leaving off axes, outline, title, etc and draw any glyphs or text you want in it. Or if you just need text, put a Bokeh `Div` – bigreddot Apr 30 '19 at 20:37