10个Python 统计报表/图表图形类库

今天介绍一些Python中用于画图表图形的类库。由于有些时候,他们跟matlab同样简单,方便。并且有些也具备非凡的表现力。php

  1. matplotlib,官网:http://matplotlib.sourceforge.net/,Matplotlib 是一个由 John Hunter 等开发的,用以绘制二维图形的 Python 模块。它利用了 Python 下的数值计算模块 Numeric 及 Numarray,克隆了许多 Matlab 中的函数, 用以帮助用户轻松地得到高质量的二维图形。Matplotlib 能够绘制多种形式的图形包括普通的线图,直方图,饼图,散点图以及偏差线图等;能够比较方便的定制图形的各类属性好比图线的类型,颜色,粗细,字体的大小 等;它可以很好地支持一部分 TeX 排版命令,能够比较美观地显示图形中的数学公式。我的比较推荐这个类库。查看例子html

  2. Cairoplot,官网:http://linil.wordpress.com/2008/09/16/cairoplot-11/,(友情提示:须要FanQiang)。Cairoplot在网页上的表现力堪比flex中的图表图形效果。可是这个彷佛只能跑在linux平台上。因此不少windows用户估计要失望了。python

  3. Chaco, 官网:http://code.enthought.com/chaco/,Chaco是一个2D的绘图库。其中文简单教程参考:http://hyry.dip.jp/pydoc/chaco_intro.htmllinux

  4. Python Google Chart,官网:http://pygooglechart.slowchop.com/。从命名方式来看,这个确定与google chart扯上了关系。因此该类库是对Google chart API的一个完整封装。c++

  5. PyCha,官网:https://bitbucket.org/lgs/pycha/wiki/Home。PyCha但是说是Cairo 类库的一个简单封装,为了是实现轻量级,以及容易使用,固然还作了一些优化等。git

  6. pyOFC2,官网:http://btbytes.github.com/pyofc2/。它是Open Falsh Library的Python类库。因此图形具备Flash效果,能够随鼠标移动动态显示图标中信息,这是优越于其余静态图示的。github

  7. Pychart,官网:http://home.gna.org/pychart/。pyChart是用于建立高品质封装的PostScript,PDF格式,PNG,或SVG图表Python库。segmentfault

  8. PLPlot,官网:http://plplot.sourceforge.net/。PLPlot是用于建立科学图表的跨平台软件包。以C类库为核心,支持各类语言绑定(C, C++, Fortran, Java, Python, Perl etc.)。开源免费。windows

  9. reportlab,官网:http://www.reportlab.com/software/opensource/。这个咱们以前介绍过,参考http://www.codecho.com/installation-and-example-of-reportlab-in-python/。这个类库支持在pdf中画图表。wordpress

  10. Vpython,官网:http://www.vpython.org/index.html,VPython是Visual Python的简写,Visual是由Carnegie Mellon University(卡耐基-梅隆大学)在校学生David Scherer于2000年撰写的一个Python 3D绘图模块。

  11. Gallery

         http://bokeh.pydata.org/gallery.html         https://github.com/ContinuumIO/Bokeh/tree/master/examples

------------------------

吐槽一下:
pyCha 图标过于简单,并且颜色过于单一,更重要的是,还须要Cairo的支持,但是如今可以庆用的Cario很少。
Python Goolge Chart是几个代码中最简单的,图标无数据。只管美观,不实用。
matplotlib,太过复杂,光光可用的模块,就不下40-50,看得真晕。
最后,测试ChartDirector,最好。但是商业软件,生成的图像还有一个黄Banner。悲催呀~

----------------------------------

下面举个 ChartDirector  的例子(注意 ChartDirector 包含 python、php、perl、c++等各类版本,这里用python示范):

#!/usr/bin/python
from pychartdir import *

# The data for the line chart
data0 = [60.2, 51.7, 81.3, 48.6, 56.2, 68.9, 52.8,60.2, 51.7, 81.3, 48.6, 56.2, 68.9]
data1 = [30.0, 32.7, 33.9, 29.5, 32.2, 28.4, 29.8,30.0, 32.7, 33.9, 29.5, 32.2, 28.4, 29.8]
labels = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat","Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]

# Create a XYChart object of size 300 x 180 pixels, with a pale yellow (0xffffc0)
# background, a black border, and 1 pixel 3D border effect.
c = XYChart(1000, 800, 0xffffc0, 0x000000, 1)

# Set the plotarea at (45, 35) and of size 240 x 120 pixels, with white background.
# Turn on both horizontal and vertical grid lines with light grey color (0xc0c0c0)
c.setPlotArea(45, 35, 900, 700, 0xffffff, -1, -1, 0xc0c0c0, -1)

# Add a legend box at (45, 12) (top of the chart) using horizontal layout and 8 pts
# Arial font Set the background and border color to Transparent.
c.addLegend(10, 742, 0, "", 18).setBackground(Transparent)

# Add a title to the chart using 9 pts Arial Bold/white font. Use a 1 x 2 bitmap
# pattern as the background.
c.addTitle("Server Load (Jun 01 - Jun 07)", "arialbd.ttf", 9, 0xffffff
    ).setBackground(c.patternColor([0x004000, 0x008000], 2))

# Set the y axis label format to nn%
# c.yAxis().setLabelFormat("{value}%")
c.yAxis().setLabelFormat("{value}")

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

# Add a line layer to the chart
layer = c.addLineLayer()

# Add the first line. Plot the points with a 7 pixel square symbol
layer.addDataSet(data0, 0xcf4040, "Peak").setDataSymbol(SquareSymbol, 7)

# Add the second line. Plot the points with a 9 pixel dismond symbol
layer.addDataSet(data1, 0x40cf40, "Average").setDataSymbol(DiamondSymbol, 9)

# Enable data label on the data points. Set the label format to nn%.
layer.setDataLabelFormat("{value}")

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

 


推荐阅读:

[1] 2013年度Python数据模块

http://segmentfault.com/a/1190000000424711

[2] 55种开源数据可视化工具简介

http://t.cn/RA879rv

[3] 让效率“爆表”的49个数据可视化工具

http://weibo.com/p/1001603836173314294816

相关文章
相关标签/搜索