| commit 109: | c28ff86ecdc3 |
| parent 108: | 69d799869e9b |
| child 110: | 12571643208b |
Fix typo
Lorenzo Gil Sánchez /
lgs
17 months ago
17 months ago
NB: This is not the latest revision. For the latest view, go to tip.
| filename | size | last modified | ||
|---|---|---|---|---|
| bin | ||||
| chavier | ||||
| doc | ||||
| examples | ||||
| src | ||||
| tests | ||||
| AUTHORS | 58 B | 2 years ago | Preparing for release | |
| CHANGES.txt | 1.1 KB | 17 months ago | Fix typo | |
| COPYING | 7.5 KB | 2 years ago | Added LGPL license | |
| README.txt | 4.9 KB | 17 months ago | Prepare for release | |
| RELEASE.howto | 3.7 KB | 2 years ago | Add a small release howto so I do not forget how to do it | |
| pycha.kpf | 298 B | 2 years ago | First import | |
| setup.py | 1.6 KB | 17 months ago | Prepare for release |
README
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | .. contents::
=====
PyCha
=====
Pycha is a very simple Python package for drawing charts using the great
`Cairo <http://www.cairographics.org/>`_ library. Its goals are:
* Lightweight
* Simple to use
* Nice looking with default values
* Customization
It won't try to draw any possible chart on earth but draw the most common ones
nicely. There are some other options you may want to look at like
`pyCairoChart <http://bettercom.de/de/pycairochart>`_.
Pycha is based on `Plotr <http://solutoire.com/plotr/>`_ which is based on
`PlotKit <http://www.liquidx.net/plotkit/>`_. Both libraries are written in
JavaScript and are great for client web programming. I needed the same for the
server side so that's the reason I ported Plotr to Python. Now we can deliver
charts to people with JavaScript disabled or embed them in PDF reports.
Pycha is distributed under the terms of the `GNU Lesser General Public License
<http://www.gnu.org/licenses/lgpl.html>`_.
Documentation
=============
Installation
------------
Pycha needs PyCairo to works since it uses the Cairo graphics library. If you
use Linux you will probably already have it installed so you don't have to do
anything. If you use Windows these are the recommended steps for installing
PyCairo:
1. Grab the latest PyCairo Windows installer from
http://ftp.gnome.org/pub/GNOME/binaries/win32/pycairo/ You need to use the
one that matches your Python version so take the one ending in -py2.4.exe
for Python 2.4 or the one ending in -py2.5.exe for Python 2.5
2. Install it in your Python environment (just follow the installation
program instructions)
3. Put the Cairo dlls inside the pycairo directory inside your site-packages
directory or anywhere in your path. You can find the dlls at
http://www.gimp.org/%7Etml/gimp/win32/downloads.html Go there and download
the following packages:
1. cairo.zip. You just need the libcairo-2.dll file inside that zip
2. libpng.zip. You just need the libpng13.dll file inside that zip
3. zlib.zip. You just need the zlib1.dll file inside that zip
Pycha is distributed as a Python Egg so is quite easy to install. You just need
to type the following command:
easy_install pycha
And Easy Install will go to the Cheeseshop and grab the last pycha for you. If
will also install it for you at no extra cost :-)
Tutorial
--------
Using pycha is quite simple. You always follow the same 5 simple steps:
1. Create a Cairo surface to draw the chart on
2. Build a list of data sets from which your chart will be created
3. Customize the chart options.
4. Create the chart, add the datasets and render it
5. Save the results into a file or do whatever you want with the Cairo
surface
To create the Cairo surface you just need to say the type of surface and its
dimensions::
import cairo
width, height = (500, 400)
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
Then you should create your data set querying a database or any other data
source::
dataSet = (
('dataSet 1', ((0, 1), (1, 3), (2, 2.5))),
('dataSet 2', ((0, 2), (1, 4), (2, 3))),
('dataSet 3', ((0, 5), (1, 1), (2, 0.5))),
)
As you can see, each data set is a tuple where the first element is the name of
the data set and the second is another tuple composed by points. Each point is a
two-elements tuple, the first one is the x value and the second the y value.
Not every chart uses all the information of a data set. For example, the Pie
chart only uses the first point of each dataset and it only uses the y value of
the point.
Now you may want to specify some options so the chart can be customize changing
its defaults values. To see the defaults you can check the
pycha.chart.Chart.__init__ method in the source code. You can use regular
dictionaries to define your options. For example, imagine you want to hide the
legend and use a different color for the background::
options = {
'legend': {'hide': True},
'background': {'color': '#f0f0f0'},
}
Now we are ready to instantiate the chart, add the data set and render it::
import pycha.bar
chart = pycha.bar.VerticalBarChart(surface, options)
chart.addDataset(dataSet)
chart.render()
Right now you can choose among 4 different kind of charts:
* Pie Charts (pycha.pie.PieChart)
* Vertical Bar Charts (pycha.bar.VerticalBarChart)
* Horizontal Bar Charts (pycha.bar.HorizontalBarChart)
* Line Charts (pycha.bar.LineChart)
* Scatterplot Charts (pycha.scatter.ScatterplotChart)
Finally you can write the surface to a graphic file or anything you want using
the cairo library::
surface.write_to_png('output.png')
That's it! You can see more examples in the examples directory of the source
code.
Documentation
-------------
Adam Przywecki has done a fantastic work writing documentation for Pycha.
Check it out at http://pycha.yourwei.com/
Development
-----------
You can get the last bleeding edge version of pycha by getting a checkout of
the subversion repository::
svn co http://www.lorenzogil.com/svn/pycha/trunk pycha
Don't forget to check the
`Release Notes <http://www.lorenzogil.com/projects/pycha/wiki/ReleaseNotes/>`_
for each version to learn the new features and incompatible changes.
Contact
-------
There is a mailing list about PyCha at http://groups.google.com/group/pycha
You can join it to ask questions about its use or simply to talk about its
development. Your ideas and feedback are greatly appreciated!
|
