Computer Graphics in Python ebook

By Martin McBride, 2019-11-09
Tags: vector graphics bezier curve colour text font font style text metrics alignment path subpath gradient radial gradient transform rotation scaling clipping masking compositing
Categories: book pycairo

Buy now from Leanpub, Amazon, Apple Books, Barnes and Noble, kobo, or other stores.

Download a free preview.

The Pycairo library is a Python graphics library. This book covers the library in detail, with lots of practical code examples.

PyCairo is an efficient, fully featured, high quality graphics library, with similar drawing capabilities to other vector libraries and languages such as SVG, PDF, HTML canvas and Java graphics.

Typical use cases include: standalone Python scripts to create an image, chart, or diagram; server side image creation for the web (for example a graph of share prices that updates hourly); desktop applications, particularly those that involve interactive images or diagrams.

The power of Pycairo, with the expressiveness of Python, is also a great combination for making procedural images such as mathematical illustrations and generative art. It is also quite simple to generate image sequences that can be converted to video or animated gifs.

This book is primarily aimed at developers who have at least a small amount of Python experience, who are looking to use Python to create computer graphics for any application. The examples in the book use basic Python constructs, you don't need to be a Python guru to learn Pycairo. No prior knowledge of computer graphics is assumed, although if you have used other graphics systems you should still find this book useful as Pycairo has its own unique quirks and features.


  • Introduction to vector graphics
  • About Pycairo
  • Basic drawing operations
  • Paths and complex shapes
  • Transforms and state
  • Colour
  • Working with text
  • Gradients, images and patterns
  • Clipping, masking and compositing
  • Output formats
  • Integration with other libraries

More information:

  • The book page on the leanpub website.
  • Signing up for the Python Informer newsletter at
  • Following @pythoninformer on twitter.
  • Contacting me directly by email (

Buy now from Leanpub, or download a free preview.

If you found this article useful, you might be interested in the book NumPy Recipes or other books by the same author.

Join the PythonInformer Newsletter

Sign up using this form to receive an email when new content is added:

Popular tags

2d arrays abstract data type alignment and angle animation arc array arrays bar chart bar style behavioural pattern bezier curve built-in function callable object chain circle classes clipping close closure cmyk colour combinations comparison operator comprehension context context manager conversion count creational pattern data science data types decorator design pattern device space dictionary drawing duck typing efficiency ellipse else encryption enumerate fill filter font font style for loop formula function function composition function plot functools game development generativepy tutorial generator geometry gif global variable gradient greyscale higher order function hsl html image image processing imagesurface immutable object in operator index inner function input installing iter iterable iterator itertools join l system lambda function latex len lerp line line plot line style linear gradient linspace list list comprehension logical operator lru_cache magic method mandelbrot mandelbrot set map marker style matplotlib monad mutability named parameter numeric python numpy object open operator optimisation optional parameter or pandas partial application path pattern permutations pie chart pil pillow polygon pong positional parameter print product programming paradigms programming techniques pure function python standard library radial gradient range recipes rectangle recursion reduce regular polygon repeat rgb rotation roundrect scaling scatter plot scipy sector segment sequence setup shape singleton slice slicing sound spirograph sprite square str stream string stroke structural pattern subpath symmetric encryption template tex text text metrics tinkerbell fractal transform translation transparency triangle truthy value tuple turtle unpacking user space vectorisation webserver website while loop zip zip_longest