本文共 1682 字,大约阅读时间需要 5 分钟。
1 安装python:
下载http://download.gna.org/pychart,解压定位到解压的目录,使用命令python setup.py install进行安装。
pychart的home:http://home.gna.org/pychart/
如:我下载的目录是C:\Documents and Settings\Administrator\My Documents\Downloads\PyChart-1.39.tar\PyChart-1.39\PyChart-1.39
安装:
C:\Documents and Settings\Administrator\My Documents\Downloads\PyChart-1.39.tar\PyChart-1.39\PyChart-1.39>python setup.py install
安装完后打开python 如果>>> import pychart不报错说明安装成功。
2学习文档和例子:
文档:http://home.gna.org/pychart/doc/index.html
例子:http://home.gna.org/pychart/examples/index.html
3 运行示例:
在Pychart的安装目录下有一系列的Demo:
C:\Documents and Settings\Administrator\My Documents\Downloads\PyChart-1.39.tar\PyChart-1.39\PyChart-1.39\demos.
本来以为直接运行就能画出图形,结果发现打印出来的是一些看不懂的数字,于是看文档,发现不是这么玩的。
To produce a PostScript chart, just feed the file to Python.
% python linetest.py >linetest.eps
Or, to produce a PDF chart, run python like below
% python linetest.py --format=pdf >linetest.pdf
例子:
from pychart import * import sys theme.get_options() theme.use_color = True can = canvas.init('pic1.png') data = [("foo", 10),("bar", 20), ("baz", 30), ("ao", 40)] ar = area.T(size=(300,300), legend=legend.T(), x_grid_style = None, y_grid_style = None) plot = pie_plot.T(data=data, arc_offsets=[0,10,0,10], shadow = (2, -2, fill_style.gray50), label_offset = 25, arrow_style = arrow.a3) ar.add_plot(plot) ar.draw()运行结果:
如果要运行自带的例子,需要安装软件gsview
http://pages.cs.wisc.edu/~ghost/gsview/get49.htm
用法如:python linetest.py >foo.eps然后用gsview打开改文件就可以看到具体的图片。但是gsview仅仅支持ps,pdf,eps等,PNG的不支持,png的要怎么搞,还得再看看
转载地址:http://rpfub.baihongyu.com/