我可以使用什么模块,而不是Bokeh V0.12.13中的Colorbar



我试图在官方文档之后使用配色栏模块编写脚本。
但是,我在下面有错误。

ImportError: cannot import name 'ColorBar'  

另外,当我查看散景github页面时,不再提供模块配色栏。
有谁知道应该如何修改以下代码以与v0.12.13兼容?

def heatmap(df,colstr):
    from math import pi
    from bokeh.io import show
    from bokeh.models import (
        ColorBar,
        ColumnDataSource,
        HoverTool,
        LinearColorMapper,
        BasicTicker,
        PrintfTickFormatter,
    )
    from bokeh.plotting import figure
    def preprocess(df,colstr):
        #temp=pd.DataFrame(df[colstr])
        df["Hour"]=df.index.hour.astype(str)
        df["Date"]=df.index.date.astype(str)
        temp=df[["Hour","Date",colstr]]
        return temp
    #add hour column and day column
    df1=preprocess(df,colstr)
    colors = ["#75968f", "#a5bab7", "#c9d9d3", "#e2e2e2", "#dfccce", "#ddb7b1", "#cc7878", "#933b41", "#550b1d"]
    mapper = LinearColorMapper(palette=colors, low=df[colstr].min(), high=df[colstr].max())
    source = ColumnDataSource(df1)
    #hard cord. better to be flexiable
    hours = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23']
    #assuming  summerdesign day and winter design day is included
    #dates = list(df1["Date"])[48:]
    dates = list(df1["Date"].drop_duplicates())[4:]
    TOOLS = "hover,save,pan,box_zoom,reset,wheel_zoom"
    p = figure(title=colstr,
               x_range=hours, y_range=list(reversed(dates)),
               x_axis_location="above", plot_width=1200, plot_height=1200,
              tools=TOOLS, toolbar_location='below')
    p.grid.grid_line_color = None
    p.axis.axis_line_color = None
    p.axis.major_tick_line_color = None
    p.axis.major_label_text_font_size = "5pt"
    p.axis.major_label_standoff = 0
    p.xaxis.major_label_orientation = pi / 3
    p.rect(x="Hour", y="Date", width=1, height=1,
           source=source,
           fill_color={'field': colstr, 'transform': mapper},
           line_color=None)

    color_bar = ColorBar(color_mapper=mapper, major_label_text_font_size="5pt",
                         ticker=BasicTicker(desired_num_ticks=len(colors)),
                         formatter=PrintfTickFormatter(format="%d%%"),
                         label_standoff=6, border_line_color=None, location=(0, 0))
    p.add_layout(color_bar, 'right')

    p.select_one(HoverTool).tooltips = [
         ('date', '@Date'),
         ('hour', '@Hour'),
    ]
    show(p)      # show the plot

ColorBar仍然存在:https://github.com/bokeh/bokeh/bokeh/blob/0.12.13/bokeh/models/models/annotations.pypy#l197

通过bokeh.models.ColorBar导入它仍在我的多个机器上的多个安装上工作。

最有可能的原因是您实际上没有使用Bokeh 0.12.13运行此代码(尽管我不确定Bokeh安装必须多大的年龄才能具有ColorBar型号(,否则您的安装是某种程度上损坏。

最新更新