phylogenie 3.1.11__py3-none-any.whl → 3.1.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
phylogenie/draw.py CHANGED
@@ -224,7 +224,7 @@ def _init_colored_tree_categorical(
224
224
  color_by: str,
225
225
  ax: Axes | None = None,
226
226
  default_color: Color = "black",
227
- colormap: str | Colormap = "tab20",
227
+ colormap: str | dict[str, Color] | Colormap = "tab20",
228
228
  show_legend: bool = True,
229
229
  labels: dict[Any, str] | None = None,
230
230
  legend_kwargs: dict[str, Any] | None = None,
@@ -242,8 +242,11 @@ def _init_colored_tree_categorical(
242
242
  The matplotlib Axes to draw on. If None, uses the current Axes.
243
243
  default_color : Color, optional
244
244
  The color to use for nodes without the specified metadata.
245
- colormap : str | Colormap, optional
246
- The colormap to use for coloring categories. Defaults to 'tab20'.
245
+ colormap : str | dict[str, Color] | Colormap, optional
246
+ The colormap to use for coloring categories.
247
+ If a string, it is used to get a matplotlib colormap.
248
+ If a dict, it maps category values to colors directly.
249
+ Defaults to 'tab20'.
247
250
  show_legend : bool, optional
248
251
  Whether to display a legend for the categories.
249
252
  labels : dict[Any, str] | None, optional
@@ -259,13 +262,16 @@ def _init_colored_tree_categorical(
259
262
  if ax is None:
260
263
  ax = plt.gca()
261
264
 
265
+ features = {node: node[color_by] for node in tree if color_by in node.metadata}
262
266
  if isinstance(colormap, str):
263
267
  colormap = plt.get_cmap(colormap)
268
+ if isinstance(colormap, Colormap):
269
+ feature_colors = {
270
+ f: mcolors.to_hex(colormap(i)) for i, f in enumerate(set(features.values()))
271
+ }
272
+ else:
273
+ feature_colors = colormap
264
274
 
265
- features = {node: node[color_by] for node in tree if color_by in node.metadata}
266
- feature_colors = {
267
- f: mcolors.to_hex(colormap(i)) for i, f in enumerate(set(features.values()))
268
- }
269
275
  colors = {
270
276
  node: feature_colors[features[node]] if node in features else default_color
271
277
  for node in tree
@@ -294,7 +300,7 @@ def draw_colored_tree_categorical(
294
300
  ax: Axes | None = None,
295
301
  backward_time: bool = False,
296
302
  default_color: Color = "black",
297
- colormap: str | Colormap = "tab20",
303
+ colormap: str | dict[str, Color] | Colormap = "tab20",
298
304
  show_legend: bool = True,
299
305
  labels: dict[Any, str] | None = None,
300
306
  legend_kwargs: dict[str, Any] | None = None,
@@ -316,8 +322,11 @@ def draw_colored_tree_categorical(
316
322
  If True, the x-axis is inverted to represent time going backward.
317
323
  default_color : Color, optional
318
324
  The color to use for nodes without the specified metadata.
319
- colormap : str | Colormap, optional
320
- The colormap to use for coloring categories. Defaults to 'tab20'.
325
+ colormap : str | dict[str, Color] | Colormap, optional
326
+ The colormap to use for coloring categories.
327
+ If a string, it is used to get a matplotlib colormap.
328
+ If a dict, it maps category values to colors directly.
329
+ Defaults to 'tab20'.
321
330
  show_legend : bool, optional
322
331
  Whether to display a legend for the categories.
323
332
  labels : dict[Any, str] | None, optional
@@ -360,7 +369,7 @@ def draw_colored_dated_tree_categorical(
360
369
  color_by: str,
361
370
  ax: Axes | None = None,
362
371
  default_color: Color = "black",
363
- colormap: str | Colormap = "tab20",
372
+ colormap: str | dict[str, Color] | Colormap = "tab20",
364
373
  show_legend: bool = True,
365
374
  labels: dict[Any, str] | None = None,
366
375
  legend_kwargs: dict[str, Any] | None = None,
@@ -381,8 +390,11 @@ def draw_colored_dated_tree_categorical(
381
390
  The matplotlib Axes to draw on. If None, uses the current Axes.
382
391
  default_color : Color, optional
383
392
  The color to use for nodes without the specified metadata.
384
- colormap : str | Colormap, optional
385
- The colormap to use for coloring categories. Defaults to 'tab20'.
393
+ colormap : str | dict[str, Color] | Colormap, optional
394
+ The colormap to use for coloring categories.
395
+ If a string, it is used to get a matplotlib colormap.
396
+ If a dict, it maps category values to colors directly.
397
+ Defaults to 'tab20'.
386
398
  show_legend : bool, optional
387
399
  Whether to display a legend for the categories.
388
400
  labels : dict[Any, str] | None, optional
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: phylogenie
3
- Version: 3.1.11
3
+ Version: 3.1.13
4
4
  Summary: Generate phylogenetic datasets with minimal setup effort
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -1,5 +1,5 @@
1
1
  phylogenie/__init__.py,sha256=RyH_mcEXcKtELTkl9HRzWcl2ANWN-G4K0BLigqR3_B4,2888
2
- phylogenie/draw.py,sha256=-hyycRN4RyG0nzZrE4CC4bmg0PgxJOeK67rwlmFZiuc,26841
2
+ phylogenie/draw.py,sha256=z0f5g8t54DST-AxvFyNYREqpj41IhSIAjHIdrtVRH08,27449
3
3
  phylogenie/main.py,sha256=ry3B3HiwibZG3_qB58T5UhWy5dp6neYUtSqzL9LrSkA,1698
4
4
  phylogenie/mixins.py,sha256=wMwqP6zkqME9eMyzx5FS6-p9X8yW09jIC8jge8pHlkk,907
5
5
  phylogenie/msa.py,sha256=RGXxmo1WX9wi5NpEQTxMuH4zk8vM0f8A7Knm0YUJ9AI,2111
@@ -33,9 +33,9 @@ phylogenie/treesimulator/events/mutations.py,sha256=8Nqa2fg7fwaVNe5XSkGDSwp9pIKQ
33
33
  phylogenie/treesimulator/io/__init__.py,sha256=rfP-zp8SP8baq5_4dPAr10WH0W6KfoMCxdTZDCSXtzE,185
34
34
  phylogenie/treesimulator/io/newick.py,sha256=8Pr_jixByPOaVch18w-rFt62HYy0U97YMu0H-QSwIy0,3449
35
35
  phylogenie/treesimulator/io/nexus.py,sha256=zqT9dzj413z_s0hqp3Cdq5NMO6lv-zuuaJlaqzaqaB8,1847
36
- phylogenie-3.1.11.dist-info/licenses/LICENSE.txt,sha256=NUrDqElK-eD3I0WqC004CJsy6cs0JgsAoebDv_42-pw,1071
37
- phylogenie-3.1.11.dist-info/METADATA,sha256=91J5lodQcF09WeD0Oq8ljaIVEWQzoYeXvb2VDbNtQ7U,5200
38
- phylogenie-3.1.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
39
- phylogenie-3.1.11.dist-info/entry_points.txt,sha256=BBH8LoReHnNFnvq4sROEsVFegfkKJ6c_oHZ7bgK7Jl4,52
40
- phylogenie-3.1.11.dist-info/top_level.txt,sha256=1YGZJhKA9tN9qI0Hcj6Cn_sOoDpba0HQlNcgQTjMD-8,11
41
- phylogenie-3.1.11.dist-info/RECORD,,
36
+ phylogenie-3.1.13.dist-info/licenses/LICENSE.txt,sha256=NUrDqElK-eD3I0WqC004CJsy6cs0JgsAoebDv_42-pw,1071
37
+ phylogenie-3.1.13.dist-info/METADATA,sha256=k0zK6rE7YTrt5ulq4i8doSKb-TH5GqoGdKmFt-Zam8c,5200
38
+ phylogenie-3.1.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
39
+ phylogenie-3.1.13.dist-info/entry_points.txt,sha256=BBH8LoReHnNFnvq4sROEsVFegfkKJ6c_oHZ7bgK7Jl4,52
40
+ phylogenie-3.1.13.dist-info/top_level.txt,sha256=1YGZJhKA9tN9qI0Hcj6Cn_sOoDpba0HQlNcgQTjMD-8,11
41
+ phylogenie-3.1.13.dist-info/RECORD,,