2

编辑:原始问题中的代码是指已过时多年的 Bokeh 版本。但是下面的答案已经更新,以回答现代版本 Bokeh 的相同问题


具有标称轴类型的散景图

from bokeh.plotting import *
from bokeh.objects import *
output_notebook()

label = ['United States', 'Russia', 'South Africa', 'Europe (average)', 'Canada', 'Austalia', 'Japan']
number = [1, 2, 3, 4, 5, 6, 7]
value = [700, 530, 400, 150, 125, 125, 75]
yr = Range1d(start=0, end=800)

figure(y_range=yr)
rect(number, [x/2 for x in value] , width=0.5, height=value, color = "#ff1200")
show()

我想在条形图中用区域标记条形Bokeh Plot。如何绘制带有类(名义或有序)的图表?请参阅示例http://en.wikipedia.org/wiki/File:Incarceration_Rates_Worldwide_ZP.svg

注意:我正在使用Python v.2.7.6and IPython v.1.2.1

4

1 回答 1

10

您需要将标签作为x_range=label并用于p.xaxis.major_label_orientation设置标签方向...

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

output_file("bar.html")

label = ['United States', 'Russia', 'South Africa', 'Europe (average)', 'Canada', 'Austalia', 'Japan']
value = [700, 530, 400, 150, 125, 125, 75]

p = figure(x_range=label, y_range=(0, 800))
p.xaxis.major_label_orientation = np.pi/4   # radians, "horizontal", "vertical", "normal"

p.vbar(x=label, top=value , width=0.5, color = "#ff1200")

show(p)

在此处输入图像描述

干杯。

于 2014-04-15T14:25:50.073 回答