【发布时间】:2019-06-11 03:48:43
【问题描述】:
在使用 Bokeh 创建绘图对象后,我需要交换绘图的 x 轴和 y 轴。我尝试按如下方式执行此操作,但收到以下 javascript 错误:
Javascript 错误:无法读取未定义的属性“长度”
我认为这可能是因为这种散景issue 与相关的PR 和gist。
我想知道我在这里缺少什么(或不理解)才能让它发挥作用。
import bokeh.plotting
import bokeh.io
def swap_axes(plot):
old_x_axis, old_y_axis = plot.below[0], plot.left[0]
old_x_range, old_y_range = plot.x_range, plot.y_range
old_x_scale, old_y_scale = plot.x_scale, plot.y_scale
plot.below = []
plot.left = []
plot.add_layout(old_y_axis, 'below')
plot.add_layout(old_x_axis, 'left')
plot.x_range, plot.y_range = old_y_range, old_x_range
plot.x_scale, plot.y_scale = old_y_scale, old_x_scale
plot.center = plot.center[::-1]
return plot
fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
counts = [5, 3, 4, 2, 4, 6]
p = bokeh.plotting.figure(x_range=fruits, plot_height=250, title="Fruit Counts",
toolbar_location=None, tools="")
p.vbar(x=fruits, top=counts, width=0.9)
bokeh.io.show(p)
bokeh.io.show(swap_axes(p))
【问题讨论】: