开发者

How to fill colors in piechart using Pychart

I am using python Pychart. I have done the follow开发者_开发百科ing 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. How can I do that?


Add theme.use_color = True before the call to get_options().

For the theme documentation:

use_color

The default value of this variable is False. If the value is True, PyChart colorizes some of the default objects. If the value is False, PyChart uses gray scale for the color of these objects.


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.

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

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

List of colors

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜