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的要怎麼搞,還得再看看