首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有自动布局功能的轴上的多级(分组)标签

具有自动布局功能的轴上的多级(分组)标签
EN

Stack Overflow用户
提问于 2017-07-24 15:37:46
回答 2查看 1.3K关注 0票数 0

在bokeh中是否可以在一个轴上有多个级别的标签?也就是说,对于像这样的数据源

代码语言:javascript
复制
TheBars | ThFoos | TheValues
--------|--------|----------
Bar     | Barfoo | 5
Bar     | Bargoo | 6
Bar     | Barhoo | 7
Foo     | Foobar | 1
Foo     | Foocar | 2

..。组BarFoo中的所有列不仅要分组在一起,而且要有一个共同的组标签贴在轴上。在Excel呈现的示例中:

我目前正在使用bokeh.models.CategoricalColorMapper在视觉上分离分组,并使用数据源中的排序来使分组粘合在一起。这个很好用,不过我也想要标签。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-07-25 04:37:09

有关此功能的文档可在此处查看:

http://docs.bokeh.org/en/latest/docs/user_guide/categorical.html

代码语言:javascript
复制
from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource, FactorRange
from bokeh.plotting import figure

output_file("bars.html")

fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
years = ['2015', '2016', '2017']

data = {'fruits' : fruits,
        '2015'   : [2, 1, 4, 3, 2, 4],
        '2016'   : [5, 3, 3, 2, 4, 6],
        '2017'   : [3, 2, 4, 4, 5, 3]}

# this creates [ ("Apples", "2015"), ("Apples", "2016"), ("Apples", "2017"), ("Pears", "2015), ... ]
x = [ (fruit, year) for fruit in fruits for year in years ]
counts = sum(zip(data['2015'], data['2016'], data['2017']), ()) # like an hstack

source = ColumnDataSource(data=dict(x=x, counts=counts))

p = figure(x_range=FactorRange(*x), plot_height=250, title="Fruit Counts by Year",
           toolbar_location=None, tools="")

p.vbar(x='x', top='counts', width=0.9, source=source)

p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xaxis.major_label_orientation = 1
p.xgrid.grid_line_color = None

show(p)

票数 2
EN

Stack Overflow用户

发布于 2017-10-09 21:26:41

我想知道拉动是不是已经完成了?我不能在v0.12.7中复制多级轴,包括所有提到的分类教程链接。

结果:

代码语言:javascript
复制
    ValueError: expected an element of either List(String) 
    or List(Int), got [('3', '6'), ('1', '6'), ('1', '4'), ('3', '3'), ('1', '8'), ('2', '6'), ('3', '4'), ('2', '5'), ('2', '4')]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45274734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档