我正在使用python Pychart。 我已经完成了以下代码来生成饼图:
from pychart import *
import sys
data = [("foo", 10),("bar", 20), ("baz", 30), ("ao", 40)]
theme.get_options()
ar = area.T(size=(150,150), legend=legend.T(),
x_grid_style = None, y_grid_style = None)
plot = pie_plot.T(data=data, arc_offsets=[0,0,0,0],
shadow = (0, 0, fill_style.gray50),
label_offset = 25,
arrow_style = arrow.a3)
ar.add_plot(plot)
ar.draw()
它生成带有灰度的饼图。 而不是灰度,我想在饼图中使用不同的颜色。 我怎么能这样做?
答案 0 :(得分:2)
在调用get_options()之前添加theme.use_color = True
。
主题文档:
<强> use_color 强>
此变量的默认值为 假。如果值为True,则为PyChart 着色一些默认对象。 如果值为False,则PyChart使用 灰度为这些颜色 对象。
答案 1 :(得分:1)
看起来pychart自2006年以来一直没有更新,我建议您查看matplotlib,或许 最好的python绘图库。
饼图示例here
答案 2 :(得分:1)
您必须使用fill_styles
参数指定填充颜色(此列表的len应与数据长度相同):
from pychart import *
import sys
data = [("foo", 10),("bar", 20), ("baz", 30), ("ao", 40)]
theme.get_options()
ar = area.T(size=(150,150), legend=legend.T(),
x_grid_style = None, y_grid_style = None)
plot = pie_plot.T(data=data, arc_offsets=[0,0,0,0],
fill_styles = [fill_style.red, fill_style.blue, fill_style.green, fill_style.yellow],
shadow = (0, 0, fill_style.gray50),
label_offset = 25,
arrow_style = arrow.a3)
ar.add_plot(plot)
ar.draw()
它将以颜色工作:)