marsilea 0.3.6__py3-none-any.whl → 0.4.1__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.
marsilea/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  """Declarative creation of composable visualization"""
2
2
 
3
- __version__ = "0.3.6"
3
+ __version__ = "0.4.1"
4
4
 
5
5
  import marsilea.plotter as plotter
6
6
  from ._deform import Deformation
marsilea/base.py CHANGED
@@ -15,7 +15,7 @@ from matplotlib.figure import Figure
15
15
 
16
16
  from ._deform import Deformation
17
17
  from .dendrogram import Dendrogram
18
- from .exceptions import SplitTwice
18
+ from .exceptions import SplitTwice, DuplicatePlotter
19
19
  from .layout import CrossLayout, CompositeCrossLayout
20
20
  from .plotter import RenderPlan, Title, SizedMesh
21
21
  from .utils import pairwise, batched, get_plot_name, _check_side
@@ -67,21 +67,22 @@ class LegendMaker:
67
67
  """
68
68
  raise NotImplementedError("Should be implemented in derived class")
69
69
 
70
- def custom_legend(self, legend, name=None):
70
+ def custom_legend(self, legend_func, name=None):
71
71
  """Add a custom legend
72
72
 
73
73
  Parameters
74
74
  ----------
75
75
 
76
- legend : `Artist <matplotlib.artist.Artists>`
77
- A legend object
76
+ legend_func : Callable
77
+ A function that return the legend object,
78
+ the legend must be an `Artist <matplotlib.artist.Artists>`
78
79
  name : str, optional
79
80
  The name of the legend
80
81
 
81
82
  """
82
83
  if name is None:
83
84
  name = str(uuid4())
84
- self._user_legends[name] = [legend]
85
+ self._user_legends[name] = legend_func
85
86
 
86
87
  def add_legends(
87
88
  self,
@@ -159,7 +160,8 @@ class LegendMaker:
159
160
  self.layout.remove_legend_ax()
160
161
 
161
162
  def _legends_drawer(self, ax):
162
- legends = {**self.get_legends(), **self._user_legends}
163
+ user_legends = {k: [v()] for k, v in self._user_legends.items()}
164
+ legends = {**self.get_legends(), **user_legends}
163
165
 
164
166
  # force to remove all legends before drawing
165
167
  # In case some legends are added implicitly
@@ -330,6 +332,8 @@ class WhiteBoard(LegendMaker):
330
332
  If True, the legend will be included when calling :meth:`~marsilea.base.LegendMaker.add_legends`
331
333
 
332
334
  """
335
+ if plot.name is not None:
336
+ raise DuplicatePlotter(plot)
333
337
  plot_name = get_plot_name(name, side, plot.__class__.__name__)
334
338
  self._legend_switch[plot_name] = legend
335
339
 
@@ -819,6 +823,9 @@ class ClusterBoard(WhiteBoard):
819
823
  )
820
824
  self._row_den = []
821
825
  self._col_den = []
826
+ cluster_data = np.asarray(cluster_data)
827
+ if cluster_data.ndim != 2:
828
+ raise ValueError("Cluster data must be 2D array")
822
829
  self._cluster_data = cluster_data
823
830
  self._deform = Deformation(cluster_data)
824
831
 
@@ -1041,7 +1048,8 @@ class ClusterBoard(WhiteBoard):
1041
1048
  warnings.warn(
1042
1049
  DeprecationWarning(
1043
1050
  "`hsplit` will be deprecated in v0.5.0, use `cut_rows` or `group_rows` instead"
1044
- )
1051
+ ),
1052
+ stacklevel=2,
1045
1053
  )
1046
1054
  if self._split_row:
1047
1055
  raise SplitTwice(axis="horizontally")
@@ -1108,7 +1116,8 @@ class ClusterBoard(WhiteBoard):
1108
1116
  warnings.warn(
1109
1117
  DeprecationWarning(
1110
1118
  "`vsplit` will be deprecated in v0.5.0, use `cut_cols` or `group_cols` instead"
1111
- )
1119
+ ),
1120
+ stacklevel=2,
1112
1121
  )
1113
1122
  if self._split_col:
1114
1123
  raise SplitTwice(axis="vertically")
@@ -1293,20 +1302,20 @@ class ClusterBoard(WhiteBoard):
1293
1302
  if deform.is_col_split:
1294
1303
  for plan in self._col_plan:
1295
1304
  if plan.allow_split:
1296
- if deform.is_col_cluster:
1297
- group_ratios = None
1298
- else:
1299
- group_ratios = plan.get_split_regroup()
1305
+ # if deform.is_col_cluster:
1306
+ # group_ratios = None
1307
+ # else:
1308
+ group_ratios = plan.get_split_regroup()
1300
1309
  self.layout.vsplit(plan.name, w_ratios, wspace, group_ratios)
1301
1310
 
1302
1311
  # split row axes
1303
1312
  if deform.is_row_split:
1304
1313
  for plan in self._row_plan:
1305
1314
  if plan.allow_split:
1306
- if deform.is_row_cluster:
1307
- group_ratios = None
1308
- else:
1309
- group_ratios = plan.get_split_regroup()
1315
+ # if deform.is_row_cluster:
1316
+ # group_ratios = None
1317
+ # else:
1318
+ group_ratios = plan.get_split_regroup()
1310
1319
  self.layout.hsplit(plan.name, h_ratios, hspace, group_ratios)
1311
1320
 
1312
1321
  def _render_dendrogram(self):
marsilea/exceptions.py CHANGED
@@ -6,6 +6,18 @@ class DuplicateName(Exception):
6
6
  return f"Axes with name `{self.name}` already exists."
7
7
 
8
8
 
9
+ class DuplicatePlotter(Exception):
10
+
11
+ def __init__(self, plotter):
12
+ self.plotter = plotter
13
+
14
+ def __str__(self):
15
+ name = self.plotter.__class__.__name__
16
+ return (f"You have added `{name}` "
17
+ f"to the `{self.plotter.side}`, "
18
+ f"please create a new `{name}` if you want to add it again.")
19
+
20
+
9
21
  class SplitTwice(Exception):
10
22
  def __init__(self, axis="col"):
11
23
  self.axis = axis
marsilea/plotter/base.py CHANGED
@@ -538,6 +538,10 @@ class RenderPlan:
538
538
  self._split_regroup = ratio
539
539
 
540
540
  def get_split_regroup(self):
541
+ if self._split_regroup is None:
542
+ return None
543
+ if self.is_flank:
544
+ return self._split_regroup[::-1]
541
545
  return self._split_regroup
542
546
 
543
547
 
marsilea/utils.py CHANGED
@@ -74,7 +74,10 @@ def get_colormap(cmap):
74
74
  try:
75
75
  return mpl.colormap.get(cmap)
76
76
  except AttributeError:
77
- return mpl.cm.get_cmap(cmap)
77
+ try:
78
+ return mpl.cm.get_cmap(cmap)
79
+ except AttributeError:
80
+ return mpl.cm.ColormapRegistry.get_cmap(cmap)
78
81
 
79
82
 
80
83
  def get_canvas_size_by_data(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: marsilea
3
- Version: 0.3.6
3
+ Version: 0.4.1
4
4
  Summary: Declarative creation of composable visualization
5
5
  Author: Zhihang Zheng
6
6
  Author-email: Mr-Milk <yzheng@cemm.at>
@@ -1,15 +1,15 @@
1
- marsilea/__init__.py,sha256=TJ1LRb_ML9gOV-uhUijRCVqEkCZkrCk0MFgrmB5z574,541
1
+ marsilea/__init__.py,sha256=9DU80xdR6t2bZPgh2LbIhQXiEN_WCSu-kRQN8tpSGRk,541
2
2
  marsilea/_api.py,sha256=tymWZHfjhx8-0NNd9762znfdIu36NrARRweEIr5L1mA,283
3
3
  marsilea/_deform.py,sha256=SKXLvhyUrwTRAw7Fl--OpupDLk6T3S5DRfwCAdewHQs,14138
4
- marsilea/base.py,sha256=wgKuOp8GKttwqC6_YdtR7RzFdxbOc-7iVjTlY0T0h44,46192
4
+ marsilea/base.py,sha256=HSY25Ax39Vj80FxSZkg4es0YklNtFJ_DgfQzbFIJseI,46637
5
5
  marsilea/dataset.py,sha256=a0mXjPu9_tRGHofnnQaTryFpxftkfqldq_ZLXMSBf7A,4410
6
6
  marsilea/dendrogram.py,sha256=WUnV2JMSY9mPt1sfkFAEikkl2ta7xHFD13teas_iZgE,14767
7
- marsilea/exceptions.py,sha256=Wxy31eCWkoXTPwqaa7R5F7cJ3uCtzqhJXmxVqqX8eAA,661
7
+ marsilea/exceptions.py,sha256=kIXDRF8Fy-BkNqeMbLqde06PaWESuKiGCMGyDpVpWIE,1006
8
8
  marsilea/heatmap.py,sha256=lKGt0lTtziNFDsb_SBfFt3zoYzVYRzezc9aae5RxHyk,4168
9
9
  marsilea/layers.py,sha256=puXLlGGpEqAzaTqadpgpsYmIDPH33WyyHIuysRSqFZQ,12163
10
10
  marsilea/layout.py,sha256=X8MGPlAbbr7dcZiqW4pI7sEb8U3jVaiS7t1DKOqMYLI,27758
11
11
  marsilea/upset.py,sha256=U1Rsmo1WpCAV9z3LBlE2L4T0nAW9ols8Z36fXzmXycw,30388
12
- marsilea/utils.py,sha256=IaAaOBdE668XuGiA-k_gmOtHYqfpIxPv_-molMSBPfs,2851
12
+ marsilea/utils.py,sha256=hp241iWBZX1JO-xqMWJ_oGa5D7y-6ETwYHvWxCYO9Us,2957
13
13
  marsilea/plotter/__init__.py,sha256=n1E53C5oqnsHZcXAtN6HgZsZdcAvANONNx-fupTxzN0,738
14
14
  marsilea/plotter/_images.py,sha256=RWCI4FhcxJZimLrhdy9CHw3ri1kweGRICUyByE4wzmg,3065
15
15
  marsilea/plotter/_seaborn.py,sha256=aK0EnboshfNCNvNjsIc7dxDE_4KBKi4HMUt7CKWt_6U,8188
@@ -17,11 +17,11 @@ marsilea/plotter/_utils.py,sha256=Efhdk-TrrAanhbXRiEVWThMYvZ4vVHZMVYMs5X3JvIM,71
17
17
  marsilea/plotter/arc.py,sha256=PFXlJ0TBIJ1mEB-lIl-Zs2UdEXkLSwDlRJbsSa5Ss5U,8165
18
18
  marsilea/plotter/area.py,sha256=zjjAhvgKHYe9rqzcseqZqhwfpgvzm0w2FRJ_vr9Fxm4,2650
19
19
  marsilea/plotter/bar.py,sha256=TeX6li--kE9NtqCRflDTX0jkG1-uIq0Dn8ILKSv-AuA,12080
20
- marsilea/plotter/base.py,sha256=0UiJqNefv9mieMB0ICpKQ2rXqGaFYigqyxQe4BzBP24,20321
20
+ marsilea/plotter/base.py,sha256=NgaoFnbMS6Mj4BghVcGaSYYN8A9e3DD_rRomDIm4C5c,20456
21
21
  marsilea/plotter/bio.py,sha256=_pZkGoAei7eirFCpu7AcZJhebBneNjUKcZlI36bpqUE,5044
22
22
  marsilea/plotter/mesh.py,sha256=ArioOXZJpD1T2wrYDmm_cFQpUmq_3q7W_qrJ_zCX3zU,23793
23
23
  marsilea/plotter/text.py,sha256=oYJ5py3_nGHKi60DSVzFgPg4drnTSTw__IcYs0cut4M,36222
24
- marsilea-0.3.6.dist-info/LICENSE,sha256=2TLD8FnLJqXzg8YBRs7W3VZBwfWfp4ArDfBl-rn96Qc,1074
25
- marsilea-0.3.6.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
26
- marsilea-0.3.6.dist-info/METADATA,sha256=COXhGBcv1dJZ9uI_TuMX3FV5dun7yTkAkw0orGCeFjQ,4074
27
- marsilea-0.3.6.dist-info/RECORD,,
24
+ marsilea-0.4.1.dist-info/LICENSE,sha256=2TLD8FnLJqXzg8YBRs7W3VZBwfWfp4ArDfBl-rn96Qc,1074
25
+ marsilea-0.4.1.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
26
+ marsilea-0.4.1.dist-info/METADATA,sha256=Ve7H7WVLlM0KAY01MhecegkMBYL9vP99vznsTt42_BY,4074
27
+ marsilea-0.4.1.dist-info/RECORD,,