background preloader

Grafy

Facebook Twitter

An Introduction to Cairo with Python. Cairo is a library for drawing vector graphics.

An Introduction to Cairo with Python

Vector graphics are interesting because they don't lose clarity when resized or transformed. Pycairo is a set of bindings for cairo. It provides the cairo module which can be used to call cairo commands from Python. The best way to understand how to use cairo is to imagine that you are an artist using a paintbrush to draw out a shape on canvas. To begin, you can choose a few characteristics of your brush. Once you have chosen your brush, you are ready to start painting. Firstly, decide where you want to place your brush on the canvas.

More complex graphics are generated using variations of the above theme with a few additions such as Fills (colouring in), transformations (zooming in, moving) etc. Nearly all the work revolves around using the cairo.Context (or cairo_t the cairo C API) . #! Other pycairo resources (tutorials, examples) are available. Wiki Pages - python-graph - A library for working with graphs in Python. IGraph library. GraphApi. This wiki page is a resource for some brainstorming around the possibility of a Python Graph API in the form of an informational PEP, similar to PEP 249, the Python DB API.

GraphApi

The goal would be, in other words, to define how a graph (or various kinds of graphs) would be expected to behave (possibly from different perspectives) in order to increase interoperability among graph algorithms. The numeric array interface, recently developed by the Numeric Python community to increase interoperability between array-handling software, illustrates the general idea. A comp.lang.python thread discussing this (with some useful ideas) may be found here. This is not about plotting; for a definition of the kind of graph we're talking about, see here. If you have interest in this, please feel free to add your ideas here. A simple use-case Just to illustrate the point of this discussion, here is a simple example: Preliminary ideas General thoughts NetworkX is another example of a graph library in Python. Tutorial — python-igraph v0.6 documentation. This chapter contains a short overview of igraph‘s capabilities. It is highly recommended to read it at least once if you are new to igraph.

I assume that you have already installed igraph; if you did not, see Installing igraph first. Familiarity with the Python language is also assumed; if this is the first time you are trying to use Python, there are many good Python tutorials on the Internet to get you started. Mark Pilgrim’s Dive Into Python is one that I personally suggest. If this is the first time you ever try to use a programming language, A Byte of Python is even better.

Starting igraph igraph is a Python module, hence it can be imported exactly the same way as any other ordinary Python module at the Python prompt: $ python Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import igraph >>> import igraph>>> print igraph. Creating a graph from scratch Warning Note.