在散景条形图中选择条形顺序 [英] Choosing order of bars in Bokeh bar chart

查看:72
本文介绍了在散景条形图中选择条形顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为尝试学习使用Bokeh的一部分,我试图制作一个简单的条形图.我按一定顺序(一周中的几天)传递标签,而Bokeh似乎是按字母顺序对它们进行排序.如何使条形图按原始列表的顺序显示?

As part of trying to learn to use Bokeh I am trying to make a simple bar chart. I am passing the labels in a certain order (days of the week) and Bokeh seems to be sorting them alphabetically. How can I have the bars show up in the order of the original list?

from bokeh.plotting import show
from bokeh.io import output_notebook
from bokeh.charts import Bar
from collections import OrderedDict
import calendar 

output_notebook()

data = OrderedDict()
data['values'] = [2,3,4,5,6,7,8] #values only ascending to make correct graph clear
data['days'] = [calendar.day_name[i-1] for i in range(7)]
p = Bar(data, label='days', values='values', 
         title='OrderedDict Input',xlabel="Day", ylabel="Value")
show(p)

生成的输出

推荐答案

我不喜欢条形图之类的高级图表.它们不是非常可定制的. 手工"构建它们通常更容易-无需花费更长的时间.这就是我要做的:

I am no big fan of high level charts such as Bar plots. They are not very customizable. Building them 'by hand' is often easier -and not necessary much longer. This is what I would do:

from bokeh.plotting import figure
from bokeh.io import output_file, show
import calendar

values = [2,3,4,5,6,7,8]
days = [calendar.day_name[i-1] for i in range(1,8)]

p = figure(x_range=days)
p.vbar(x=days, width=0.5, top=values, color = "#ff1200")

output_file('foo.html')
show(p)

产生:

这篇关于在散景条形图中选择条形顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆