我想用范围工具创建一个条形图,因为 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', ...)