Skip to main content

Chalk is a declarative drawing library. The API draws heavy inspiration from Haskell's diagrams, Scala's doodle and Jeremy Gibbons's lecture notes on Functional Programming for Domain−Specific Languages.

The documentation is available at https://chalk-diagrams.github.io.

⚠️ The library is still very much work in progress and subject to change.

Installation

The library is available on PyPI as chalk-diagrams and can be installed with pip:

pip install git+https://github.com/chalk-diagrams/chalk/

On Debian (or Colab) you will need to install Cairo for PyCairo

sudo apt-get install libcairo2-dev

If you want to use the LaTeX extension, run:

pip install chalk-diagrams[latex]

For the LaTeX extension you might need to install pdf2svg and texlive; on Debian these dependencies can be installed as follows:

sudo apt-get install pdf2svg texlive texlive-science texlive-latex-recommended texlive-latex-extra

Installation with Conda

You can install the library with conda from conda-forge channel.

conda install -c conda-forge chalk-diagrams

Overview

Below we provide a brief introduction of the main functionality of the library. These examples are available in the examples/intro.py file.

We start by importing the colour module and the diagrams functions:

from colour import Color
from chalk import *

We also define some colors that will be shortly used:

papaya = Color("#ff9700")
blue = Color("#005FDB")

We can easily create basic shapes (the functions circle, square, triangle) and style them with various attributes (the methodsfill_color, line_color, line_width). For example:

d = circle(1).fill_color(papaya)

circle

The diagram can be saved to an image using the render method:

d.render("examples/output/intro-01.png", height=64)

We can glue together two diagrams using the combinators atop (or +), beside (or |), above (or /). For example:

circle(0.5).fill_color(papaya) | square(1).fill_color(blue)

which is equivalent to

circle(0.5).fill_color(papaya).beside(square(1).fill_color(blue))

This code produces the following image:

atop

We also provide combinators for a list of diagrams: hcat for horizontal composition, vcat for vertical composition. For example:

hcat(circle(0.1 * i) for i in range(1, 6)).fill_color(blue)

hcat

We can use Python functions to build more intricate diagrams:

def sierpinski(n: int, size: int) -> Diagram:
    if n <= 1:
        return triangle(size)
    else:
        smaller = sierpinski(n - 1, size / 2)
        return smaller.above(smaller.beside(smaller).center_xy())

d = sierpinski(5, 4).fill_color(papaya)

sierpinski

For more examples, please check the examples folder; their output is illustrated below:


squares.py

logo.py

escher_square_limit.py

hilbert.py

koch.py

hex-variation.py

lenet.py

tensor.py

hanoi.py

tree.py

lattice.py

These scripts can be run as follows:

python examples/squares.py

Authors

Special thanks to:

  • Sugato Ray, for his significant contributions and suggestions;
  • Ionuț G. Stan, for providing many useful insights and comments.

Metadata

Release files for chalk-diagrams 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chalk-diagrams 0.2.2
File Size Uploaded Provenance Actions
chalk_diagrams-0.2.2.tar.gz 37.8 kB Without provenance Details for chalk_diagrams-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chalk-diagrams 0.2.2
File Interpreter ABI Platform Actions
chalk_diagrams-0.2.2-py3-none-any.whl Python 3 none any Details for chalk_diagrams-0.2.2-py3-none-any.whl

Total release size: 82.3 kB

Release files / chalk_diagrams-0.2.2.tar.gz

Download URL chalk_diagrams-0.2.2.tar.gz
Size 37.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2c7ebebc4c09d00a27d91955d9294962fa0ea676b2a3d098ac3d22b3b6e70af0
BLAKE2b-256 checksum
How to use checksums
f648ee3220b0d37dba0ff03aa719a66bd02248891fa62d491aab99a816c6f885
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.5

Release files / chalk_diagrams-0.2.2-py3-none-any.whl

Download URL chalk_diagrams-0.2.2-py3-none-any.whl
Size 44.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06020b24d90759fe996fd19151f2dc04814c970b002bdfb83e047785729f85d6
BLAKE2b-256 checksum
How to use checksums
88e20bf40389cccf147df96c710cf9923ad83a2ab17dff52d8434321d93bdec4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.5

Security for chalk-diagrams 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page