From b3a9a9b5d5577c597de48373b3616819a2d66b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Guignard?= Date: Thu, 4 Dec 2025 11:24:46 +0100 Subject: [PATCH 1/2] update min max --- src/lineagetree/measure/uted.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lineagetree/measure/uted.py b/src/lineagetree/measure/uted.py index 84a9104..987bb7e 100644 --- a/src/lineagetree/measure/uted.py +++ b/src/lineagetree/measure/uted.py @@ -6,6 +6,7 @@ from itertools import combinations from typing import TYPE_CHECKING, Literal +import numpy as np import matplotlib.colors as mcolors from edist import uted from matplotlib import colormaps @@ -360,6 +361,8 @@ def plot_tree_distance_graphs( size: float = 10, lw: float = 0.3, ax: list[plt.Axes] | None = None, + vmin=None, + vmax=None, ) -> tuple[plt.figure, plt.Axes]: """ Plots the subtrees compared and colors them according to the quality of the matching of their subtree. @@ -509,7 +512,11 @@ def plot_tree_distance_graphs( if ax is None: fig, ax = plt.subplots(nrows=1, ncols=2, sharey=True) cmap = colormaps[colormap] - c_norm = mcolors.Normalize(0, 1) + if vmin is None: + vmin = np.percentile(list(colors.values()), 5) + if vmax is None: + vmax = np.percentile(list(colors.values()), 95) + c_norm = mcolors.Normalize(vmin, vmax) colors = {c: cmap(c_norm(v)) for c, v in colors.items()} lT.plot_subtree( lT.get_ancestor_at_t(n1), From f70eb7192e59bee0c4677386e75311b3cab37089 Mon Sep 17 00:00:00 2001 From: BadPrograms Date: Tue, 9 Dec 2025 15:23:07 +0100 Subject: [PATCH 2/2] fix vmin-vmax --- src/lineagetree/lineage_tree_manager.py | 13 ++++++++++++- src/lineagetree/measure/uted.py | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/lineagetree/lineage_tree_manager.py b/src/lineagetree/lineage_tree_manager.py index 4673107..7b713df 100644 --- a/src/lineagetree/lineage_tree_manager.py +++ b/src/lineagetree/lineage_tree_manager.py @@ -515,6 +515,8 @@ def plot_tree_distance_graphs( size: float = 10, lw: float = 0.3, ax: np.ndarray | None = None, + vmin=None, + vmax=None, ) -> tuple[plt.figure, plt.Axes]: """ Plots the subtrees compared and colors them according to the quality of the matching of their subtree. @@ -552,6 +554,11 @@ def plot_tree_distance_graphs( The width of the edges, defaults to 0.3 ax : np.ndarray, optional The axes used, if not provided another set of axes is produced, defaults to None + vmin, vmax: float, optional + Values within the range ``[vmin, vmax]`` from the input data will be + linearly mapped to ``[0, 1]``. + *vmin* defaults to the 0.05 quantile of the values of the unordered tree edist distances of the subtrees. + *vmax* defaults to the 0.95 quantile of the values of the unordered tree edist distances of the subtrees. Returns ------- @@ -699,7 +706,11 @@ def plot_tree_distance_graphs( if ax is None: fig, ax = plt.subplots(nrows=1, ncols=2) cmap = colormaps[colormap] - c_norm = mcolors.Normalize(0, 1) + if vmin is None: + vmin = np.percentile(list(colors1.values()), 5) + if vmax is None: + vmax = np.percentile(list(colors1.values()), 95) + c_norm = mcolors.Normalize(vmin, vmax) colors1 = {c: cmap(c_norm(v)) for c, v in colors1.items()} colors2 = {c: cmap(c_norm(v)) for c, v in colors2.items()} tree1.lT.plot_subtree( diff --git a/src/lineagetree/measure/uted.py b/src/lineagetree/measure/uted.py index 987bb7e..719db07 100644 --- a/src/lineagetree/measure/uted.py +++ b/src/lineagetree/measure/uted.py @@ -395,6 +395,11 @@ def plot_tree_distance_graphs( The width of the edges, defaults to 0.3 ax : np.ndarray, optional The axes used, if not provided another set of axes is produced, defaults to None + vmin, vmax: float, optional + Values within the range ``[vmin, vmax]`` from the input data will be + linearly mapped to ``[0, 1]``. + *vmin* defaults to the 0.05 quantile of the values of the unordered tree edist distances of the subtrees. + *vmax* defaults to the 0.95 quantile of the values of the unordered tree edist distances of the subtrees. Returns -------