drawing tools for Demes demographic models
Project description
DemesDraw
demesdraw is a Python package that contains drawing functions for
Demes
demographic models, using matplotlib to create the figures.
DemesDraw offers both a command line interface, and a Python API.
Feedback is very welcome.
Installation
Install with pip:
$ python3 -m pip install demesdraw
Or with conda:
$ conda install -c conda-forge demesdraw
Example usage
Command line interface (CLI)
The CLI can be used to quickly plot a Demes YAML file. Any image format supported by matplotlib can be specified as the output, but a vector format such as svg or pdf is recommended.
demesdraw tubes --log-time \
examples/stdpopsim/HomSap__AmericanAdmixture_4B11.yaml \
AmericanAdmixture_4B11_tubes.svg
Interactive plots
If an output file is not specified, then an interactive plotting window will
be shown. Hovering the mouse over parts of the plot will show an annotation.
The example below combines this with demes CLI support for ms commands,
to visualise a command from the
ms manual.
# Figure 2 from the ms manual (pp. 17 & 18 of msdoc.pdf):
# Calculate N0, the scaling parameter to convert coalescent units into
# generation times and population sizes.
N0=`python -c 'theta=11.2; mu=1e-8; length=7000; print(theta/(4*mu*length))'`
demes ms \
-N0 $N0 \
-I 2 3 12 \
-g 1 44.36 \
-n 2 0.125 \
-eg 0.03125 1 0.0 \
-en 0.0625 2 0.05 \
-ej 0.09375 2 1 \
| demesdraw tubes --scale-bar -
Python API
Compared with the CLI, the Python API provides additional control. In the following example, the horizontal positions of the demes are chosen manually and the names of extinct demes are moved to a legend.
import demes
import demesdraw
graph = demes.load("examples/stdpopsim/HomSap__AmericanAdmixture_4B11.yaml")
w = demesdraw.utils.separation_heuristic(graph)
positions = dict(ancestral=0, AMH=0, AFR=0, OOA=1.5 * w, EAS=1 * w, EUR=2 * w, ADMIX=-w)
ax = demesdraw.tubes(graph, log_time=True, positions=positions, labels="xticks-legend")
ax.figure.savefig("AmericanAdmixture_4B11_tubes_custom.svg")
Documentation
Complete API and CLI details are available in the DemesDraw documentation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file demesdraw-0.4.1.tar.gz.
File metadata
- Download URL: demesdraw-0.4.1.tar.gz
- Upload date:
- Size: 299.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0fc5d49759187aaa750a98ff60fc0821397e5876bc6fd8b7b689a75e7d00f0b
|
|
| MD5 |
4a466263de9603d770a095a6ae13d099
|
|
| BLAKE2b-256 |
0a6ea489b1029c8a167ff461d737d9ebc60e2ce868e13455b571c567e2fa0eac
|
Provenance
The following attestation bundles were made for demesdraw-0.4.1.tar.gz:
Publisher:
wheel.yaml on grahamgower/demesdraw
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
demesdraw-0.4.1.tar.gz -
Subject digest:
b0fc5d49759187aaa750a98ff60fc0821397e5876bc6fd8b7b689a75e7d00f0b - Sigstore transparency entry: 583838346
- Sigstore integration time:
-
Permalink:
grahamgower/demesdraw@e126f78ae3e0af54bacd4a5008e15a62b66bfac5 -
Branch / Tag:
refs/tags/0.4.1 - Owner: https://github.com/grahamgower
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheel.yaml@e126f78ae3e0af54bacd4a5008e15a62b66bfac5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file demesdraw-0.4.1-py3-none-any.whl.
File metadata
- Download URL: demesdraw-0.4.1-py3-none-any.whl
- Upload date:
- Size: 23.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
023cf309ec5587b99f2edf85396e76eafd5f6492a5deaec85d91515367c4d2e5
|
|
| MD5 |
3edc52acf22e17b2b3ead46f7e7cf9fc
|
|
| BLAKE2b-256 |
de3c9a80d239cbad95418816187cb39bd946ec78b8552e8704ff692d50327674
|
Provenance
The following attestation bundles were made for demesdraw-0.4.1-py3-none-any.whl:
Publisher:
wheel.yaml on grahamgower/demesdraw
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
demesdraw-0.4.1-py3-none-any.whl -
Subject digest:
023cf309ec5587b99f2edf85396e76eafd5f6492a5deaec85d91515367c4d2e5 - Sigstore transparency entry: 583838348
- Sigstore integration time:
-
Permalink:
grahamgower/demesdraw@e126f78ae3e0af54bacd4a5008e15a62b66bfac5 -
Branch / Tag:
refs/tags/0.4.1 - Owner: https://github.com/grahamgower
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheel.yaml@e126f78ae3e0af54bacd4a5008e15a62b66bfac5 -
Trigger Event:
release
-
Statement type: