为了账号安全,请及时绑定邮箱和手机立即绑定

如果它是 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 关注
  • 115 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信