如何在更改轴尺寸的同时固定Bokeh vbar图表的尺寸?

时间:2019-04-30 15:30:06

标签: bokeh axis-labels sizing

我使用bokeh中的“列”布局将2个vbar图表彼此堆叠。这两个vbar图表共享相同的x轴和x,y范围。

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)

尽管p1和p2的范围和图宽/高度相同,但我们有不同的条形图(p1的条形图较大),因为一个带有轴标签,而另一个没有轴标签。现在,如何将p1,p2的条形图设置为相同大小?

1 个答案:

答案 0 :(得分:1)

从Bokeh 1.1开始,没有直接方法可以直接指定内部绘图框的大小,而只能指定整个外部画布的大小。但是,您可以指定min_border_bottom,以确保绘图框下方的空间(通常由轴刻度和标签占用的空间)始终至少为某个最小尺寸:

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

因此您可以:

  • 将相同的合适min_border_bottom传递给两个图,以确保两个图始终在图框下方保留相同数量的空间(无论是否有轴)。

  • 将合适的min_border_bottom传递到带有轴的图,并从不带有轴的图的plot_height中减去相同的值。