def model_image(self, species, model): import demesdraw import matplotlib.pyplot as plt mid = self.get_demographic_model_id(species, model) _, ax = plt.subplots(1, 1, figsize=(4, 4), tight_layout=True) # Conversion into demes object for easier plotting graph = model.model.to_demes() demesdraw.tubes(graph, ax=ax, log_time=True) ax.set_title(f"{model.id}", fontsize=10) ax.set_xticklabels( [p.name for p in model.populations], rotation=45, ha="right", rotation_mode="anchor", fontsize=10, ) ax.set_ylabel("Time (generations)", fontsize=10) os.makedirs(f"parameter_images/{species.id}/", exist_ok=True) img_name = f"parameter_images/{species.id}/{mid}.png" plt.savefig(img_name, dpi=150) section = nodes.image(uri=img_name) return section
#!/usr/bin/env python3 import demes import demesdraw def size_max(graph): return max( max(epoch.start_size, epoch.end_size) for deme in graph.demes for epoch in deme.epochs) graph = demes.load("models/IM.yaml") w = 0.8 * size_max(graph) positions = dict(A=0, X=-w, Y=w) fig, ax = demesdraw.utils.get_fig_axes(aspect=1) ax = demesdraw.tubes(graph, ax=ax, positions=positions, seed=1, inf_ratio=0.4) ax.figure.savefig( "fig/IM.pdf", # Save with a transparent background. transparent=True, )
def draw_model(args): dg = demes.load(args.yaml) outfile = os.path.basename(args.yaml).replace(".yml", "_draw.png") _ = demesdraw.tubes(dg) plt.savefig(outfile) return outfile