简体   繁体   English

如何使用Pychart在饼图中填充colors

[英]How to fill colors in piechart using Pychart

I am using python Pychart.我正在使用 python Pychart。 I have done the following code to generate pie chart:我已经完成了以下代码来生成饼图:

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

It generates the pie chart with gray scale.它生成带有灰度的饼图。 Instead of gray-scale, I want different colors in pie chart.我想要饼图中不同的 colors 而不是灰度。 How can I do that?我怎样才能做到这一点?

Add theme.use_color = True before the call to get_options().在调用 get_options() 之前添加theme.use_color = True

For the theme documentation:对于主题文档:

use_color使用颜色

The default value of this variable is False.此变量的默认值为 False。 If the value is True, PyChart colorizes some of the default objects.如果值为 True,PyChart 会为一些默认对象着色。 If the value is False, PyChart uses gray scale for the color of these objects.如果值为 False,PyChart 使用灰度来表示这些对象的颜色。

Looks like pychart haven't been updated since 2006, I would recommend that you have a look at matplotlib , perhaps the best plotting library for python.看起来 pychart 自 2006 年以来就没有更新过,我建议您查看matplotlib ,这可能是 python最佳绘图库。

Pie-chart example here饼图示例在这里

You have to specify the filling colors with the fill_styles argument (len of this list should be the same as the data length):您必须使用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()

and it will work in colors:)它将在 colors 中工作:)

List of colors colors列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM