iplotx 0.6.6__py3-none-any.whl → 0.6.8__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.
iplotx/plotting.py
CHANGED
|
@@ -29,6 +29,7 @@ def network(
|
|
|
29
29
|
aspect: Optional[str | float] = None,
|
|
30
30
|
margins: float | tuple[float, float] = 0,
|
|
31
31
|
strip_axes: bool = True,
|
|
32
|
+
figsize: Optional[tuple[float, float]] = None,
|
|
32
33
|
**kwargs,
|
|
33
34
|
) -> list[mpl.artist.Artist]:
|
|
34
35
|
"""Plot this network and/or vertex grouping using the specified layout.
|
|
@@ -55,6 +56,9 @@ def network(
|
|
|
55
56
|
a fraction of the data limits, so 0.1 means 10% of the data limits will be left
|
|
56
57
|
as margin.
|
|
57
58
|
strip_axes: If True, remove axis spines and ticks.
|
|
59
|
+
figsize: If ax is None, a new matplotlib Figure is created. This argument specifies
|
|
60
|
+
the (width, height) dimension of the figure in inches. If ax is not None, this
|
|
61
|
+
argument is ignored. If None, the default matplotlib figure size is used.
|
|
58
62
|
kwargs: Additional arguments are treated as an alternate way to specify style. If
|
|
59
63
|
both "style" and additional **kwargs are provided, they are both applied in that
|
|
60
64
|
order (style, then **kwargs).
|
|
@@ -71,7 +75,7 @@ def network(
|
|
|
71
75
|
raise ValueError("At least one of network or grouping must be provided.")
|
|
72
76
|
|
|
73
77
|
if ax is None:
|
|
74
|
-
fig, ax = plt.subplots()
|
|
78
|
+
fig, ax = plt.subplots(figsize=figsize)
|
|
75
79
|
|
|
76
80
|
artists = []
|
|
77
81
|
if network is not None:
|
|
@@ -135,6 +139,7 @@ def tree(
|
|
|
135
139
|
aspect: Optional[str | float] = None,
|
|
136
140
|
margins: float | tuple[float, float] = 0,
|
|
137
141
|
strip_axes: bool = True,
|
|
142
|
+
figsize: Optional[tuple[float, float]] = None,
|
|
138
143
|
**kwargs,
|
|
139
144
|
) -> TreeArtist:
|
|
140
145
|
"""Plot a tree using the specified layout.
|
|
@@ -143,10 +148,37 @@ def tree(
|
|
|
143
148
|
tree: The tree to plot. Can be a BioPython.Phylo.Tree object.
|
|
144
149
|
layout: The layout to use for plotting.
|
|
145
150
|
directed: If False, do not draw arrows.
|
|
151
|
+
vertex_labels: The labels for the vertices. If None or False, no vertex labels. Also
|
|
152
|
+
read leaf_labels for leaf nodes.
|
|
153
|
+
leaf_labels: The labels for the leaf nodes. If None or False, no leaf labels are used
|
|
154
|
+
except if vertex_labels are specified for leaf nodes. This argument and the
|
|
155
|
+
previous vertex_labels provide somewhat redundant functionality but have quite
|
|
156
|
+
different default behaviours for distinct use cases. This argument is typically
|
|
157
|
+
useful for labels that are specific to leaf nodes only (e.g. species in a
|
|
158
|
+
phylogenetic tree), whereas vertex_labels is typically used for labels that apply
|
|
159
|
+
to internal nodes too (e.g. branch support values). This redundancy is left on
|
|
160
|
+
purpose to allow for maximal style flexibility.
|
|
146
161
|
show_support: If True, show the support values for the nodes (assumed to be from 0 to 100,
|
|
147
162
|
rounded to nearest integer). If both this parameter and vertex_labels are set,
|
|
148
163
|
show_support takes precedence and hides the vertex labels.
|
|
164
|
+
ax: The axis to plot on. If None, a new figure and axis will be created. Defaults to
|
|
165
|
+
None.
|
|
166
|
+
style: Apply this style for the objects to plot. This can be a sequence (e.g. list)
|
|
167
|
+
of styles and they will be applied in order.
|
|
168
|
+
title: If not None, set the axes title to this value.
|
|
169
|
+
aspect: If not None, set the aspect ratio of the axis to this value. The most common
|
|
170
|
+
value is 1.0, which proportionates x- and y-axes.
|
|
171
|
+
margins: How much margin to leave around the plot. A higher value (e.g. 0.1) can be
|
|
172
|
+
used as a quick fix when some vertex shapes reach beyond the plot edge. This is
|
|
173
|
+
a fraction of the data limits, so 0.1 means 10% of the data limits will be left
|
|
174
|
+
as margin.
|
|
149
175
|
strip_axes: If True, remove axis spines and ticks.
|
|
176
|
+
figsize: If ax is None, a new matplotlib Figure is created. This argument specifies
|
|
177
|
+
the (width, height) dimension of the figure in inches. If ax is not None, this
|
|
178
|
+
argument is ignored. If None, the default matplotlib figure size is used.
|
|
179
|
+
kwargs: Additional arguments are treated as an alternate way to specify style. If
|
|
180
|
+
both "style" and additional **kwargs are provided, they are both applied in that
|
|
181
|
+
order (style, then **kwargs).
|
|
150
182
|
|
|
151
183
|
Returns:
|
|
152
184
|
A TreeArtist object, set as a direct child of the matplotlib Axes.
|
|
@@ -155,7 +187,7 @@ def tree(
|
|
|
155
187
|
|
|
156
188
|
with stylecontext:
|
|
157
189
|
if ax is None:
|
|
158
|
-
fig, ax = plt.subplots()
|
|
190
|
+
fig, ax = plt.subplots(figsize=figsize)
|
|
159
191
|
|
|
160
192
|
artist = TreeArtist(
|
|
161
193
|
tree=tree,
|
iplotx/tree.py
CHANGED
|
@@ -311,13 +311,21 @@ class TreeArtist(mpl.artist.Artist):
|
|
|
311
311
|
if not leaf_style.get("deep", True):
|
|
312
312
|
return
|
|
313
313
|
|
|
314
|
+
# Given the conditions above, we should have leaf labels. If not,
|
|
315
|
+
# make a None series with a valid index
|
|
316
|
+
leaf_label_series = self._get_label_series("leaf")
|
|
317
|
+
if leaf_label_series is None:
|
|
318
|
+
leaf_label_series = self._ipx_internal_data["leaf_df"].copy()
|
|
319
|
+
leaf_label_series["label"] = None
|
|
320
|
+
leaf_label_series = leaf_label_series["label"]
|
|
321
|
+
|
|
314
322
|
edge_style = get_style(
|
|
315
323
|
".leafedge",
|
|
316
324
|
)
|
|
317
325
|
default_style = {
|
|
318
326
|
"linestyle": "--",
|
|
319
327
|
"linewidth": 1,
|
|
320
|
-
"
|
|
328
|
+
"color": "#111",
|
|
321
329
|
}
|
|
322
330
|
for key, value in default_style.items():
|
|
323
331
|
if key not in edge_style:
|
|
@@ -335,14 +343,24 @@ class TreeArtist(mpl.artist.Artist):
|
|
|
335
343
|
else:
|
|
336
344
|
cmap_fun = None
|
|
337
345
|
|
|
338
|
-
leaf_shallow_layout = self.get_layout("leaf")
|
|
339
|
-
|
|
340
346
|
if "cmap" in edge_style:
|
|
341
347
|
colorarray = []
|
|
342
348
|
edgepatches = []
|
|
343
349
|
adjacent_vertex_ids = []
|
|
344
|
-
for i, vid in enumerate(
|
|
345
|
-
|
|
350
|
+
for i, (vid, label) in enumerate(leaf_label_series.items()):
|
|
351
|
+
# Use leaf label to compute backup key for style rotation
|
|
352
|
+
# NOTE: This is quite a common use case. Users typically
|
|
353
|
+
# refer to leaves via their labels because that's what you see
|
|
354
|
+
# on screen. While an object exact match should take priority
|
|
355
|
+
# for power users, a backup based on label is useful. Beginners
|
|
356
|
+
# won't stumble upon this anyway since it's only used if
|
|
357
|
+
# a dict-like property for leaf edges is provided, which is a
|
|
358
|
+
# decently advanced thing to do.
|
|
359
|
+
# NOTE: Multiple leaves might have the same label, in which case
|
|
360
|
+
# all leaves will be style matched to this *unless* the dict-like
|
|
361
|
+
# style object *also* matches on leaf objects directly, which
|
|
362
|
+
# takes precedence since key2 is only a fallback.
|
|
363
|
+
edge_stylei = rotate_style(edge_style, index=i, key=vid, key2=label)
|
|
346
364
|
|
|
347
365
|
if cmap_fun is not None:
|
|
348
366
|
colorarray.append(edge_stylei["color"])
|
iplotx/version.py
CHANGED
|
@@ -5,10 +5,10 @@ iplotx/groups.py,sha256=_9KdIiTAi1kXtd2mDywgBJCbqoRq2z-5fzOPf76Wgb8,6287
|
|
|
5
5
|
iplotx/label.py,sha256=6am3a0ejcW_bWEXSOODE1Ke3AyCU1lJ45RfnXNbHAQw,8923
|
|
6
6
|
iplotx/layout.py,sha256=KxmRLqjo8AYCBAmXez8rIiLU2sM34qhb6ox9AHYwRyE,4839
|
|
7
7
|
iplotx/network.py,sha256=LaW9zQZ4sKiDVb25_icnquGNnN7HrKC7NO07o6PSmGI,11527
|
|
8
|
-
iplotx/plotting.py,sha256=
|
|
9
|
-
iplotx/tree.py,sha256
|
|
8
|
+
iplotx/plotting.py,sha256=IEUxW1xzTljLjBfsVP2BNsOPCDpj5bEPZ99bzvD5-mo,10066
|
|
9
|
+
iplotx/tree.py,sha256=-69lpPjisRfigY4fDQcmVxzOAf1tGwMXviUcW6mZU6U,28508
|
|
10
10
|
iplotx/typing.py,sha256=QLdzV358IiD1CFe88MVp0D77FSx5sSAVUmM_2WPPE8I,1463
|
|
11
|
-
iplotx/version.py,sha256=
|
|
11
|
+
iplotx/version.py,sha256=Ssoh-uTVPI9dHESTgtP5SAY8kO-o2pYIi_gVIxFJKiw,66
|
|
12
12
|
iplotx/vertex.py,sha256=-JZaQPjIAWWP8Wap1HyR4g4HXLNGLwjf4v6jyo994Tk,14671
|
|
13
13
|
iplotx/edge/__init__.py,sha256=HlxeIs88RbRrTetJNLcoq9gjV7cBhOdqQoiVZFFylFc,27081
|
|
14
14
|
iplotx/edge/arrow.py,sha256=C4XoHGCYou1z2alz5Q2VhdaWYEzgebtEF70zVYY_frk,15533
|
|
@@ -33,6 +33,6 @@ iplotx/utils/geometry.py,sha256=6RrC6qaB0-1vIk1LhGA4CfsiMd-9JNniSPyL_l9mshE,9245
|
|
|
33
33
|
iplotx/utils/internal.py,sha256=WWfcZDGK8Ut1y_tOHRGg9wSqY1bwSeLQO7dHM_8Tvwo,107
|
|
34
34
|
iplotx/utils/matplotlib.py,sha256=wELE73quQv10-1w9uA5eDTgkZkylJvjg7pd3K5tZPOo,6294
|
|
35
35
|
iplotx/utils/style.py,sha256=wMWxJykxBD-JmcN8-rSKlWcV6pMfwKgR4EzSpk_NX8k,547
|
|
36
|
-
iplotx-0.6.
|
|
37
|
-
iplotx-0.6.
|
|
38
|
-
iplotx-0.6.
|
|
36
|
+
iplotx-0.6.8.dist-info/METADATA,sha256=HorC8mcRXtF_RaDZQQbrPWtdXyBwGPTLYa5oNVViVM0,4908
|
|
37
|
+
iplotx-0.6.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
38
|
+
iplotx-0.6.8.dist-info/RECORD,,
|
|
File without changes
|