使用Python Pychart画图

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

结果发现生成的PDF根本就没有图片,或者打不开,于是在FAQ中看到需要下载Ghostscript
Q: Does pychart support Windows?
Yes. But you need to install Pythonand Ghostscriptbeforehand.
安装ghostscript之后需要在python中添加环境变量。


例子:
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的要怎么搞,还得再看看



  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

惹不起的程咬金

来都来了,不赏点银子么

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值