问题描述
我正在尝试绘制数据,其中 X 轴为字符串,Y 轴为 int,并有一个下拉列表来更改字符串以使用 js 回调更新散景图。如果我将 X 轴与字符串一起使用,它似乎无法正常工作,但如果我更改为 int(如年份),它会正确更新。下面是一个示例代码。任何帮助将不胜感激。
数据集:
import pandas as pd
from bokeh.plotting import figure,output_file,show,save
from bokeh.io import output_notebook
from bokeh.models import NumeralTickFormatter,HoverTool,ColumnDataSource,CategoricalColorMapper,Select
from bokeh.transform import factor_cmap
from bokeh.models.widgets import Tabs,Panel
from bokeh.models import Slider,CustomJS
from bokeh.layouts import row,column
gap = pd.read_csv('Users/Downloads/gapminder_tidy.csv')
gap1 = gap.loc[:,['Country','region','fertility']]
gap2 = gap1[gap1['Country'] == 'Iceland']
Overall = ColumnDataSource(data=gap1)
Curr = ColumnDataSource(data=gap2)
# plot and the menu is linked with each other by this callback function
callback = CustomJS(args=dict(source=Overall,sc=Curr),code="""
var f = cb_obj.value
sc.data['region']=[]
sc.data['fertility']=[]
for(var i = 0; i <= source.get_length(); i++){
if (source.data['Country'][i] == f){
sc.data['region'].push(source.data['Year'][i])
sc.data['fertility'].push(source.data['fertility'][i])
}
}
sc.change.emit();
""")
menu = Select(options=list(gap['Country'].unique()),value='Iceland',title='Country') # drop down menu
p = figure(x_axis_label='region',y_axis_label='fertility') # creating figure object
p.circle(x='region',top='fertility',bottom=0,color='green',source=Curr) # plotting the data using glyph circle
menu.js_on_change('value',callback) # calling the function on change of selection
layout = column(menu,p) # creating the layout
show(layout) # displaying the layout
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)