具有标称或序数轴类型的散景图

Spi*_*rou 2 python bar-chart axis-labels bokeh

编辑:原始问题中的代码是指过期的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()
Run Code Online (Sandbox Code Playgroud)

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

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

Dam*_*ila 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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

干杯.