### Configure Notebook Plotting Source: https://github.com/grahamgower/demesdraw/blob/main/docs/quickstart.md Sets the matplotlib backend to SVG format for high-quality vector rendering within Jupyter notebooks. ```python from matplotlib_inline.backend_inline import set_matplotlib_formats set_matplotlib_formats("svg") ``` -------------------------------- ### Install DemesDraw Source: https://github.com/grahamgower/demesdraw/blob/main/README.md Instructions for installing the DemesDraw package using standard Python package managers. ```bash python3 -m pip install demesdraw ``` ```bash conda install -c conda-forge demesdraw ``` -------------------------------- ### Plot Demes as Tubes Source: https://github.com/grahamgower/demesdraw/blob/main/docs/quickstart.md Generates a schematic overview of demographic models representing demes as tubes. This visualization highlights ancestor-descendant relationships and migration events. ```python import demes import demesdraw gutenkunst_ooa = demes.load("../examples/stdpopsim/HomSap__OutOfAfrica_3G09.yaml") demesdraw.tubes(gutenkunst_ooa, num_lines_per_migration=6, log_time=True, seed=1234); ``` -------------------------------- ### Plot Population Size History Source: https://github.com/grahamgower/demesdraw/blob/main/docs/quickstart.md Visualizes population size over time for demographic models. Supports log-scaling for time and size axes, and handles both single and multi-deme models. ```python import demes import demesdraw zigzag = demes.load("../examples/stdpopsim/HomSap__Zigzag_1S14.yaml") demesdraw.size_history(zigzag, invert_x=True, log_time=True); gutenkunst_ooa = demes.load("../examples/stdpopsim/HomSap__OutOfAfrica_3G09.yaml") demesdraw.size_history(gutenkunst_ooa, invert_x=True, log_size=True); ``` -------------------------------- ### Define and visualize a deme model with demesdraw Source: https://github.com/grahamgower/demesdraw/blob/main/docs/layout.md Demonstrates how to load a demes model, calculate a separation heuristic for horizontal spacing, and visualize the model using the tubes function. ```python import demes import demesdraw model2 = demes.loads( """ time_units: generations defaults: epoch: start_size: 500 demes: - name: A - name: B start_time: 100 ancestors: [A] - name: C start_time: 50 ancestors: [A] """ ) w = demesdraw.utils.separation_heuristic(model2) positions = {deme.name: j*w for j, deme in enumerate(model2.demes)} demesdraw.tubes(model2, positions=positions); ``` -------------------------------- ### Visualize Demes Models with Tubes Source: https://github.com/grahamgower/demesdraw/blob/main/docs/layout.md Demonstrates the use of the demesdraw.tubes function to visualize demographic models, including the effect of the inf_ratio parameter on time axis scaling. ```python import matplotlib.pyplot as plt import demesdraw fig, axs = plt.subplots(ncols=2, constrained_layout=True) demesdraw.tubes(model1, inf_ratio=0.2, ax=axs[0]) demesdraw.tubes(model1, inf_ratio=0.5, ax=axs[1]) ``` -------------------------------- ### Visualize Demes Models via CLI Source: https://github.com/grahamgower/demesdraw/blob/main/README.md Use the command-line interface to generate demographic model plots from YAML files or piped input. Supports various output formats and interactive windows. ```bash demesdraw tubes --log-time examples/stdpopsim/HomSap__AmericanAdmixture_4B11.yaml AmericanAdmixture_4B11_tubes.svg ``` ```bash 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 - ``` -------------------------------- ### Optimize deme positions using quadratic programming Source: https://github.com/grahamgower/demesdraw/blob/main/docs/layout.md Refines deme positions by minimizing squared distances between related demes while maintaining order constraints, utilizing the optimise_positions function. ```python positions1 = demesdraw.utils.minimal_crossing_positions( model3, sep=w, unique_interactions=False ) positions2 = demesdraw.utils.optimise_positions( model3, positions=positions1, sep=w, unique_interactions=False, ) demesdraw.tubes(model3, positions=positions2, log_time=True); ``` -------------------------------- ### Visualize Demes Models via Python API Source: https://github.com/grahamgower/demesdraw/blob/main/README.md Programmatically generate demographic model plots using the Python API for advanced control over layout, positions, and labeling. ```python 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") ``` -------------------------------- ### BibTeX Citation for DemesDraw Software Source: https://github.com/grahamgower/demesdraw/blob/main/docs/CITATION.md This BibTeX entry is for citing the DemesDraw software specifically. It includes the software title, author, version, and publication year, along with a URL for the repository. ```bibtex @misc{gower_demesdraw_2022, title = {DemesDraw: Drawing functions for {Demes} demographic models}, howpublished = {https://github.com/grahamgower/demesdraw}, author = {Gower, Graham}, version = {0.4.1}, year = 2022, } ``` -------------------------------- ### Visualize Demographic Models from YAML Source: https://github.com/grahamgower/demesdraw/blob/main/docs/examples.ipynb This script loads demographic models from YAML files and generates two types of visualizations: a size history plot and a tube plot. It uses heuristics to determine logarithmic scaling for time and population size and outputs the results as SVG figures. ```python import math import pathlib import warnings import demes import demesdraw import demesdraw.utils import matplotlib.pyplot as plt from matplotlib_inline.backend_inline import set_matplotlib_formats set_matplotlib_formats("svg") warnings.filterwarnings("ignore", "Multiple pulses", UserWarning, "demes") def plot_from_yaml(yaml_filename): graph = demes.load(yaml_filename) log_time = demesdraw.utils.log_time_heuristic(graph) log_size = demesdraw.utils.log_size_heuristic(graph) ax1 = demesdraw.size_history( graph, invert_x=True, log_time=log_time, log_size=log_size, title=example.name, ) ax2 = demesdraw.tubes( graph, log_time=log_time, title=example.name, ) plt.show(ax1.figure) plt.show(ax2.figure) plt.close(ax1.figure) plt.close(ax2.figure) cwd = pathlib.Path(".").parent.resolve() examples = list((cwd / ".." / "examples").glob("**/*.yaml")) for example in sorted(examples): plot_from_yaml(example) ``` -------------------------------- ### Automated Separation Heuristic Source: https://github.com/grahamgower/demesdraw/blob/main/docs/layout.md Uses the demesdraw.utils.separation_heuristic function to calculate optimal spacing between demes based on model complexity and population sizes. ```python w = demesdraw.utils.separation_heuristic(im) positions = {deme.name: j*w for j, deme in enumerate(im.demes)} demesdraw.tubes(im, positions=positions) ``` -------------------------------- ### Minimize line crossings in deme visualizations Source: https://github.com/grahamgower/demesdraw/blob/main/docs/layout.md Uses the minimal_crossing_positions utility to find an optimal left-to-right ordering of demes, which helps reduce visual clutter caused by crossing lines. ```python model3 = demes.load("../examples/reticulate.yaml") w = demesdraw.utils.separation_heuristic(model3) positions = demesdraw.utils.minimal_crossing_positions( model3, sep=w, unique_interactions=False ) demesdraw.tubes(model3, positions=positions, log_time=True); ``` -------------------------------- ### Customize Deme Horizontal Positioning Source: https://github.com/grahamgower/demesdraw/blob/main/docs/layout.md Manually defines the horizontal midpoint of demes using a dictionary to control the layout of the tubes plot. ```python positions = dict(A=0, B=1000, C=2000) demesdraw.tubes(model1, positions=positions, scale_bar=True) ``` -------------------------------- ### BibTeX Citation for Demes Paper Source: https://github.com/grahamgower/demesdraw/blob/main/docs/CITATION.md This BibTeX entry can be used to cite the original Demes paper. It includes details such as title, authors, journal, and publication year. ```bibtex @article{gower_demes_2022, title = {Demes: a standard format for demographic models}, url = {https://doi.org/10.1093/genetics/iyac131}, doi = {10.1093/genetics/iyac131}, journal = {Genetics}, author = {Gower, Graham and Ragsdale, Aaron P and Bisschop, Gertjan and Gutenkunst, Ryan N and Hartfield, Matthew and Noskova, Ekaterina and Schiffels, Stephan and Struck, Travis J and Kelleher, Jerome and Thornton, Kevin R}, month = sep, year = 2022, pages = {iyac131}, } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.