[英]How to fill colors in piechart using Pychart
我正在使用 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()
它生成带有灰度的饼图。 我想要饼图中不同的 colors 而不是灰度。 我怎样才能做到这一点?
在调用 get_options() 之前添加theme.use_color = True
。
对于主题文档:
使用颜色
此变量的默认值为 False。 如果值为 True,PyChart 会为一些默认对象着色。 如果值为 False,PyChart 使用灰度来表示这些对象的颜色。
看起来 pychart 自 2006 年以来就没有更新过,我建议您查看matplotlib ,这可能是 python的最佳绘图库。
饼图示例在这里
您必须使用fill_styles
参数指定填充 colors(此列表的 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()
它将在 colors 中工作:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.