Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

branch color vmax #15

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.DS_Store
*~
buck-out/
.ipynb_checkpoints/

# Compiled files
.venv/
Expand Down
8 changes: 7 additions & 1 deletion src/pycea/pl/plot_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def branches(
tree: str | Sequence[str] | None = None,
cmap: str | mcolors.Colormap = "viridis",
palette: cycler.Cycler | mcolors.ListedColormap | Sequence[str] | Mapping[str] | None = None,
vmax: int | float | None = None,
vmin: int | float | None = None,
na_color: str = "lightgrey",
na_linewidth: int | float = 1,
ax: Axes | None = None,
Expand Down Expand Up @@ -107,7 +109,11 @@ def branches(
if len(color_data) == 0:
raise ValueError(f"Key {color!r} is not present in any edge.")
if color_data.dtype.kind in ["i", "f"]:
norm = plt.Normalize(vmin=color_data.min(), vmax=color_data.max())
if not vmin:
vmin = color_data.min()
if not vmax:
vmax = color_data.max()
norm = plt.Normalize(vmin=vmin, vmax=vmax)
cmap = plt.get_cmap(cmap)
colors = [cmap(norm(color_data[edge])) if edge in color_data.index else na_color for edge in edges]
kwargs.update({"color": colors})
Expand Down
2 changes: 1 addition & 1 deletion tests/test_plot_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_polar_with_clades(tdata):

def test_angled_numeric_annotations(tdata):
pycea.pl.branches(
tdata, polar=False, color="length", cmap="hsv", linewidth="length", depth_key="time", angled_branches=True
tdata, polar=False, color="length", cmap="hsv", linewidth="length", depth_key="time", angled_branches=True, vmax = 2,
)
pycea.pl.nodes(tdata, nodes="all", color="time", style="s", size=20)
pycea.pl.nodes(tdata, nodes=["2"], tree="1", color="black", style="*", size=200)
Expand Down
Loading