Bokeh Plot with a nominal or ordinal axis type

痴心易碎 提交于 2020-01-02 11:06:11

问题


Edit: The code in the original question refers to a version of Bokeh that is years out of date. But the answer below has been updated to answer the same question for modern versions of Bokeh


Bokeh Plot with a nominal axis type

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()

I would like to label the bars with the regions in a Bokeh Plot bar chart. How can I plot a chart with classes (nominal or ordinal)? See the example http://en.wikipedia.org/wiki/File:Incarceration_Rates_Worldwide_ZP.svg.

NOTE: I'm using Python v.2.7.6 and IPython v.1.2.1.


回答1:


You need to pass the label as x_range=label and use p.xaxis.major_label_orientation to set up 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)

Cheers.



来源:https://stackoverflow.com/questions/23082912/bokeh-plot-with-a-nominal-or-ordinal-axis-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!