博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用Python Pychart画图
阅读量:2190 次
发布时间:2019-05-02

本文共 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
结果发现生成的PDF根本就没有图片,或者打不开,于是在FAQ中看到需要下载Ghostscript
Q: Does pychart support Windows?
Yes. But you need to install and beforehand.
安装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的要怎么搞,还得再看看

转载地址:http://rpfub.baihongyu.com/

你可能感兴趣的文章
探索Redis设计与实现10:Redis的事件驱动模型与命令执行过程
查看>>
分布式系统理论基础1: 一致性、2PC和3PC
查看>>
分布式系统理论基础2 :CAP
查看>>
分布式系统理论基础3: 时间、时钟和事件顺序
查看>>
分布式系统理论基础4:Paxos
查看>>
分布式系统理论基础5:选举、多数派和租约
查看>>
分布式系统理论基础6:Raft、Zab
查看>>
分布式系统理论进阶7:Paxos变种和优化
查看>>
分布式系统理论基础8:zookeeper分布式协调服务
查看>>
搞懂分布式技术1:分布式系统的一些基本概念
查看>>
搞懂分布式技术2:分布式一致性协议与Paxos,Raft算法
查看>>
搞懂分布式技术3:初探分布式协调服务zookeeper
查看>>
搞懂分布式技术4:ZAB协议概述与选主流程详解
查看>>
搞懂分布式技术5:Zookeeper的配置与集群管理实战
查看>>
搞懂分布式技术6:Zookeeper典型应用场景及实践
查看>>
搞懂分布式技术10:LVS实现负载均衡的原理与实践
查看>>
搞懂分布式技术11:分布式session解决方案与一致性hash
查看>>
搞懂分布式技术12:分布式ID生成方案
查看>>
搞懂分布式技术13:缓存的那些事
查看>>
搞懂分布式技术14:Spring Boot使用注解集成Redis缓存
查看>>