Skip to content

Commit 787a0ad

Browse files
committed
Make compose nrow & ncol attributes
1 parent 41da5fc commit 787a0ad

File tree

3 files changed

+8
-28
lines changed

3 files changed

+8
-28
lines changed

plotnine/composition/_beside.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,9 @@ class Beside(Compose):
3030
plotnine.composition.Compose : For more on composing plots
3131
"""
3232

33-
@property
34-
def nrow(self) -> int:
35-
return 1
36-
37-
@property
38-
def ncol(self) -> int:
39-
return len(self)
33+
def __post_init__(self):
34+
super().__post_init__()
35+
self.ncol = len(self)
4036

4137
def __or__(self, rhs: ggplot | Compose) -> Compose:
4238
"""

plotnine/composition/_compose.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def __post_init__(self):
109109
op if isinstance(op, Compose) else deepcopy(op)
110110
for op in self.items
111111
]
112+
self.nrow = 1
113+
self.ncol = 1
112114

113115
def __repr__(self):
114116
"""
@@ -269,20 +271,6 @@ def _repr_mimebundle_(self, include=None, exclude=None) -> MimeBundle:
269271
figure_size_px = self.last_plot.theme._figure_size_px
270272
return get_mimebundle(buf.getvalue(), format, figure_size_px)
271273

272-
@property
273-
def nrow(self) -> int:
274-
"""
275-
Number of rows in the composition
276-
"""
277-
return 0
278-
279-
@property
280-
def ncol(self) -> int:
281-
"""
282-
Number of cols in the composition
283-
"""
284-
return 0
285-
286274
@property
287275
def last_plot(self) -> ggplot:
288276
"""

plotnine/composition/_stack.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,9 @@ class Stack(Compose):
3030
plotnine.composition.Compose : For more on composing plots
3131
"""
3232

33-
@property
34-
def nrow(self) -> int:
35-
return len(self)
36-
37-
@property
38-
def ncol(self) -> int:
39-
return 1
33+
def __post_init__(self):
34+
super().__post_init__()
35+
self.nrow = len(self)
4036

4137
def __truediv__(self, rhs: ggplot | Compose) -> Compose:
4238
"""

0 commit comments

Comments
 (0)