如何使用散景从饼图中爆炸切片?

时间:2017-01-11 13:04:17

标签: python matplotlib bokeh

这是一段使用matplotlib库绘制饼图和爆炸切片的python代码

import matplotlib.pyplot as plt
values = [12, 55, 4, 32, 14]
colors = ['r', 'g', 'b', 'c', 'm']
labels = ['India', 'US', 'UK', 'Poland', 'China']
explode = [0, 0, 0.2, 0, 0]
plt.pie(values, colors = colors, labels = labels, explode = explode)
plt.show()

Like This one i want to create/plot pie chart using Bokeh

1 个答案:

答案 0 :(得分:0)

截至Bokeh 0.12.4,核心库中没有内置任何内容可以做到这一点。您当然可以使用wedge字形方法绘制这样的图表,并自己绘制单个楔形图。然后你可以将其中一个楔子的中心偏移到"爆炸"它:

from math import pi

from bokeh.plotting import figure, output_file, show

p = figure(x_range=(-1.2, 1.2), y_range=(-1.2, 1.2))

p.wedge(x=0 , y=0, radius=1, start_angle=0, end_angle=0.75*pi, color="red")
p.wedge(x=0 , y=0, radius=1, start_angle=0.75*pi, end_angle=1.05*pi, color="blue")
p.wedge(x=0 , y=0, radius=1, start_angle=1.05*pi, end_angle=1.55*pi, color="green")

# "explode" one wedge by offsetting its center
p.wedge(x=0.1 , y=-0.1, radius=1, 
        start_angle=1.55*pi, end_angle=2*pi, color="orange")


output_file("foo.html")

show(p) 

导致

enter image description here

如果您希望这是Bokeh的内置功能,请考虑在project issue tracker上发出功能请求问题。