Python 使用pycha画图表
来源:互联网 发布:sql语言属于什么语言 编辑:程序博客网 时间:2024/06/06 05:10
事前准备:
下载并安装:
Cairo:
http://www.lfd.uci.edu/~gohlke/pythonlibs/bux9zozk/pycairo-1.10.0.win32-py2.7.exe
Pycha:
https://bitbucket.org/lgs/pycha/get/e3e270a0e7ae.zip
简单的程序示例如下(包括饼图和直方图):
#!/usr/bin/env python
# -*-coding:utf-8-*-
import cairo[A1]
import pycha.pie
import pycha.bar
import pycha.stackedbar
import pycha.scatter
#设置画布
def set_surface():
width,height=700,700
surface=cairo.ImageSurface(cairo.FORMAT_ARGB32,width,height)[A2]
return surface
#饼图
def draw_pie(surface,options,dataSet):
chart=pycha.pie.PieChart(surface,options)
chart.addDataset(dataSet)
chart.render()[A3]
surface.write_to_png('D:\\Pie.png')
#垂直立方图
defdraw_vertical_bar(surface,options,dataSet):
chart=pycha.bar.HorizontalBarChart(surface,options)
chart.addDataset(dataSet)
chart.render()
surface.write_to_png('d:\\VerticalBar.png')
if __name__=='__main__':
#设置数据
dataSet=(
('IBM',((1,3),(2,4),(3,6))),
('HP',((1,3.3),(2.1,4.3),(2,5))),
('DELL',((2,3.3),(3.1,3.3),(3,5))),
)
#设置图像属性
options={
'legend':{'hide':False},
'title':'服务器销售分布图(design byWoody)',
'titleColor':'#0000ff',
'titleFont':'字体',
'background':{'chartColor':'#00fff0'},
'axis':{'labelColor':'#ff000'},
}
surface=set_surface()
#调用不同的方法生成相应的销售图表
draw_pie(surface,options,dataSet)
draw_vertical_bar(surface,options,dataSet)
运行结果图如下:
Python isPython!
[A1]
关于Cairo:
http://www.cairographics.org/
[A2]
关于ImageSurface:
Creates an image surface of the specifiedformat and dimensions. Initially the surface contents are all 0. (Specifically,within each pixel, each color or alpha channel belonging to format will be 0.The contents of bits within a pixel, but not belonging to the given format areundefined).
format :
format of pixels in the surface to create
width :
width of the surface, in pixels
height :
height of the surface, in pixels
Returns :
a pointer to the newly created surface. The caller owns the surface and should call cairo_surface_destroy() when done with it. This function always returns a valid pointer, but it will return a pointer to a "nil" surface if an error such as out of memory occurs. You can use cairo_surface_status() to check for this.
[A3]
求解中…
- Python 使用pycha画图表
- Centos 6上python pycha简易使用
- python中的外部扩展包pycha使用
- java 中使用 python外部扩展包pycha
- Python:使用pycha快速绘制办公常用图二(使用样式定制个性化图表)
- 使用Python Pychart画图
- Python使用ReportLab画图
- 使用python matplotlib画图
- python使用matplotlib画图
- 使用python画图
- Python:使用pycha快速绘制办公常用图(饼图、垂直直方图、水平直方图、散点图等七种图形)
- Python:使用pycha快速绘制办公常用图(饼图、垂直直方图、水平直方图、散点图等七种图形)
- Python:使用pycha快速绘制办公常用图(饼图、垂直直方图、水平直方图、散点图等七种图形)
- Python matplotlib画图表
- 使用python画图(2)
- 使用python画图(3)
- 使用echarts画图表
- python matplotlib画图安装和使用
- wikioi方格取数c
- JAVA——动态代理(在别人的基础上稍作改动)
- 【读书笔记】java语言与面向对象程序设计4:继承与多态
- DOM4J解析XML文档
- Linux常用命令(1):文件目录ln chmod
- Python 使用pycha画图表
- IOS如果将一个十六进制的color转换成UIColor,很实用
- android ListView之BaseAdapter的使用方式
- 也来一篇关于Infragistics WPF Report的使用教程 (二)
- Java编程思想笔记——第九章
- Cadence
- 关于投票系统刷票方式原理(突破ip限制刷票PHP版)
- POJ--如何求阶乘的位数
- 解决模式对话框和window.open打开新页面Session会丢失问题