您的位置:首页 > 编程语言 > Python开发

Python图表软件包ChartDirector的安装和使用

2014-08-18 23:28 881 查看
 


Python图表软件包ChartDirector的安装和使用

分类: Python2013-01-07
16:40 1073人阅读 评论(0) 收藏 举报

转载自http://zj.he.blog.163.com/blog/static/1068286472010925104915276/

Python平台好的图表软件不多,ChartDirector是其中较好的一个,功能丰富,使用简单,特在此分享一下安装和使用经验。
使用环境:
SUSE Enterprise Server 11
Python2.6

一、安装
1、从http://www.advsofteng.com/下载最新版安装包并解压缩

ChartDirector for Python - Software and HTML DocLinux (i386)7.3 MB
2、在/usr/local/lib/python2.6/site_packages/下建立chartdirector目录
3、将ChartDirector/lib子目录下文件复制到/usr/local/lib/python2.6/site_packages/chartdirector目录下
4、在/usr/local/lib/python2.6/site_packages/chartdirector目录下建立chartdirector.pth文件,文件内容如下:
# chartdirector packages configuration
chartdirector
5、验证安装是否成功,在python Shell中执行
>>>from pychartdir import *
如果命令正常执行,表示安装成功

二、中文问题的解决
1、安装中文字体文件
将中文字体文件mingliu.ttc、simsun.ttc复制到/usr/local/lib/python2.6/site-packages
中文字体文件可以从Windows XP的windows/fonts目录下获得
2、在程序中指定中文字体(seDefaultFonts),示例程序如下:

#!/usr/bin/python
# -*- coding: utf-8 -*-

from pychartdir import *

# The data for the bar chart
data = [85, 156, 179.5, 211, 123]

# The labels for the bar chart
labels = [u"星期一", u"星期二", u"星期三", u"星期四", u"星期五"]

# Create a XYChart object of size 500 x 500 pixels
c = XYChart(500, 500)

# Set the plotarea at (30, 20) and of size 200 x 200 pixels
c.setPlotArea(60, 40, 400, 400)

# Add a bar chart layer using the given data
c.addBarLayer(data)

# Set the labels on the x axis.
c.xAxis().setLabels(labels)

# Set Chinese fonts
c.setDefaultFonts("simsun.ttc")

# Output the chart
c.makeChart("simplebar.png")

程序输出结果



 

注意事项:
1)源代码要使用UTF-8编码 
2)中文标签都要用Unicode字符串
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: