亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如果它是 stringList,我如何更新圖形 x_range?

如果它是 stringList,我如何更新圖形 x_range?

智慧大石 2022-01-11 16:56:46
我想更改散景圖的 x 軸。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 = ["Marseille", "Paris"]  # how can i do thatpush_notebook(handle=handler)ValueError: expected an instance of type Range, got ['Marseille', 'Paris'] of type list我無法從列表中創建范圍,我該怎么辦?
查看完整描述

1 回答

?
PIPIONE

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)


查看完整回答
反對 回復 2022-01-11
  • 1 回答
  • 0 關注
  • 126 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號