1 回答

TA貢獻1829條經驗 獲得超9個贊
您已經x_range在圖形構造函數中設置了,稍后您將嘗試設置它兩次。但是你應該使用plot.x_range.factors = ["Marseille", "Paris"]:
from bokeh.plotting import show, figure
from bokeh.models import ColumnDataSource, VBar
xrange = ["Marseille", "Lyon"]
plot = figure(x_range = xrange)
plotSource = ColumnDataSource(data = dict(x = xrange, y = [1, 2]))
bars = VBar(x = "x", top = "y", width = 0.1, fill_color = "black")
plot.add_glyph(plotSource, bars)
handler = show(plot, notebook_handle = True)
plot.x_range.factors = ["Marseille", "Paris"]
show(plot)
或者,也許這是您想要的更簡單的代碼(使用您的source):
from bokeh.plotting import show, figure
from bokeh.models import ColumnDataSource
xrange = ["Marseille", "Lyon"]
p = figure(x_range = xrange)
source = ColumnDataSource(data = dict(x = xrange, y = [1, 2]))
bars = p.vbar(x = "x", top = "y", source = source, width = 0.1, fill_color = "black")
show(p)
添加回答
舉報