Bokeh Python中的错误vbar_stack



我是Bokeh的新手,我想尝试在散布中尝试VBAR_STACK,并在其文档中按照以下文档中的代码进行以下操作:

from bokeh.core.properties import value
from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
output_file("stacked.html")
fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
years = ["2015", "2016", "2017"]
colors = ["#c9d9d3", "#718dbf", "#e84d60"]
data = {'fruits' : fruits,
        '2015'   : [2, 1, 4, 3, 2, 4],
        '2016'   : [5, 3, 4, 2, 4, 6],
        '2017'   : [3, 2, 4, 4, 5, 3]}
source = ColumnDataSource(data=data)
p = figure(x_range=fruits, plot_height=250, title="Fruit Counts by Year",
           toolbar_location=None, tools="")
p.vbar_stack(years, x='fruits', width=0.9, color=colors, source=source,
             legend=[value(x) for x in years])
p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xgrid.grid_line_color = None
p.axis.minor_tick_line_color = None
p.outline_line_color = None
p.legend.location = "top_left"
p.legend.orientation = "horizontal"
show(p)

运行代码后我遇到了此错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-152-49fb8bdc8de2> in <module>()
     20            toolbar_location=None, tools="")
     21 
---> 22 p.vbar_stack(years, x='fruits', width=0.9, color=colors, source=source,
     23              legend=[value(x) for x in years])
     24 
AttributeError: 'Figure' object has no attribute 'vbar_stack'

我试图将散景升级为VER。0.12.10(最新),但是它不起作用。

您的散景版本太旧了(您使用的版本是从添加了vbar_stack之前的)。您需要更新到较新的版本。如果您认为自己已经处于一个足够的新版本,那么您可能会在多个Virutalenv或Conda环境之间遇到一些混乱,并且不会加载您打算的Bokeh版本。另外,您会有某种安装损坏(删除site-packages中与Bokeh相关的所有内容)。

最新更新