Skip to content

Commit c7b4daf

Browse files
committed
docstring, better exception messages
1 parent 34620c1 commit c7b4daf

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

fastplotlib/layouts/_engine.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,10 @@ def set_rect(self, subplot: Subplot, rect: tuple | list | np.ndarray):
284284
the subplot to set the rect of
285285
286286
rect: (x, y, w, h)
287-
as absolute pixels or fractional
287+
as absolute pixels or fractional.
288+
If width & height <= 1 the rect is assumed to be fractional.
289+
Conversely, if width & height > 1 the rect is assumed to be in absolute pixels.
290+
width & height must be > 0. Negative values are not allowed.
288291
289292
"""
290293

@@ -308,7 +311,10 @@ def set_extent(self, subplot: Subplot, extent: tuple | list | np.ndarray):
308311
the subplot to set the extent of
309312
310313
extent: (xmin, xmax, ymin, ymax)
311-
as absolute pixels or fractional
314+
as absolute pixels or fractional.
315+
If xmax & ymax <= 1 the extent is assumed to be fractional.
316+
Conversely, if xmax & ymax > 1 the extent is assumed to be in absolute pixels.
317+
Negative values are not allowed. xmax - xmin & ymax - ymin must be > 0.
312318
313319
"""
314320

fastplotlib/layouts/_figure.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,18 @@ def __init__(
6161
6262
rects: list of tuples or arrays
6363
list of rects (x, y, width, height) that define the subplots.
64-
rects can be defined in absolute pixels or as a fraction of the canvas
64+
rects can be defined in absolute pixels or as a fraction of the canvas.
65+
If width & height <= 1 the rect is assumed to be fractional.
66+
Conversely, if width & height > 1 the rect is assumed to be in absolute pixels.
67+
width & height must be > 0. Negative values are not allowed.
6568
6669
extents: list of tuples or arrays
6770
list of extents (xmin, xmax, ymin, ymax) that define the subplots.
6871
extents can be defined in absolute pixels or as a fraction of the canvas.
72+
If xmax & ymax <= 1 the extent is assumed to be fractional.
73+
Conversely, if xmax & ymax > 1 the extent is assumed to be in absolute pixels.
74+
Negative values are not allowed. xmax - xmin & ymax - ymin must be > 0.
75+
6976
If both ``rects`` and ``extents`` are provided, then ``rects`` takes precedence over ``extents``, i.e.
7077
``extents`` is ignored when ``rects`` are also provided.
7178
@@ -146,7 +153,7 @@ def __init__(
146153
subplot_names = np.asarray(names).flatten()
147154
if subplot_names.size != n_subplots:
148155
raise ValueError(
149-
"must provide same number of subplot `names` as specified by Figure `shape`"
156+
f"must provide same number of subplot `names` as specified by shape, extents, or rects: {n_subplots}"
150157
)
151158
else:
152159
if layout_mode == "grid":
@@ -206,7 +213,7 @@ def __init__(
206213
if not subplot_controllers.size == n_subplots:
207214
raise ValueError(
208215
f"number of controllers passed must be the same as the number of subplots specified "
209-
f"by shape: {n_subplots}. You have passed: {subplot_controllers.size} controllers"
216+
f"by shape, extents, or rects: {n_subplots}. You have passed: {subplot_controllers.size} controllers"
210217
) from None
211218

212219
for index in range(n_subplots):
@@ -278,7 +285,7 @@ def __init__(
278285

279286
if controller_ids.size != n_subplots:
280287
raise ValueError(
281-
"Number of controller_ids does not match the number of subplots"
288+
f"Number of controller_ids does not match the number of subplots: {n_subplots}"
282289
)
283290

284291
if controller_types is None:

0 commit comments

Comments
 (0)