在具有类别值的 Bokeh 中使用 range_tool

问题描述 投票:0回答:0

我想用范围工具创建一个条形图,因为 x 轴有很多类别。

这是一个示例代码,我尝试使用散景中基于

AccountID
的范围工具创建条形图,但它没有用:

from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource, RangeTool
from bokeh.plotting import figure

# Sample data
AccountID = ['A1233', 'B3453', 'C1213', 'D1241']
Value = [10, 20, 30, 40]

source = ColumnDataSource(data=dict(x=Account, y=Value))

p = figure(x_range=x, height=400, title="Bar Chart")
p.vbar(x='x', top='y', width=0.9, source=source)

range_tool = figure(height=130, x_range=p.x_range, y_range=(0, max(y)))
range_tool.vbar(x='x', top='y', width=0.9, source=source)

p.y_range.callback = RangeTool(x_range=range_tool.x_range).callback

output_file("bar_chart_with_range_tool.html")

show(p)

会报错:

ValueError: failed to validate RangeTool(id='p2528', ...).x_range: expected either None or a value of type Instance(Range1d), got FactorRange(id='p2430', ...)

如何在散景中创建这样的条形图Bar plot with range_tool

python bokeh
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.