nautechsystems/nautilus_trader · error · ValueError
Grid has cells but charts were configured; provide a larger…
Error message
Grid has {rows * cols} cells but {len(charts)} charts were configured; provide a larger GridLayout via TearsheetConfig.layout What it means
_calculate_grid_layout checks that the TearsheetConfig GridLayout (rows * cols) has enough cells for every configured chart. If len(charts) exceeds the grid capacity, a ValueError is raised telling the user to enlarge the layout.
Solutions
- Increase rows/cols in TearsheetConfig.layout so rows*cols >= number of charts
- Remove charts from the config so they fit the grid
- Omit the layout and let the default sizing logic choose
Example fix
// before cfg = TearsheetConfig(layout=GridLayout(rows=2, cols=2)) # 5 charts -> ValueError // after cfg = TearsheetConfig(layout=GridLayout(rows=3, cols=2)) # 6 cells for 5 charts
Defensive patterns
Strategy: validation
Validate before calling
rows, cols = cfg.layout.rows, cfg.layout.cols
assert len(charts) <= rows * cols, \
f"Need {len(charts)} cells, grid has {rows * cols}" Try / catch
try:
fig = create_tearsheet_from_stats(stats, config=cfg)
except ValueError as e:
if "cells but" in str(e):
cfg = replace(cfg, layout=auto_sized_layout(len(charts)))
fig = create_tearsheet_from_stats(stats, config=cfg)
else:
raise Prevention
- Derive rows*cols from len(charts) instead of hardcoding the grid
- Update layout whenever charts are added or removed
- Test tearsheet configs with their layouts together
When it happens
Trigger: Configuring TearsheetConfig(layout=GridLayout(rows=2, cols=2)) while passing more than 4 TearsheetChart objects to create_tearsheet_from_stats.
Common situations: Adding charts to a tearsheet config without updating the fixed grid; loading a saved config whose layout predates newly added charts; registering extra custom charts that land in the grid.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Chart renderer must be callable, was
- Colors dict missing required keys
- must not be None
- Theme name cannot be empty
- 'bbo_side_type' and 'bbo_level' must be provided together
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/f3367b2a5d02fa12.
Report an issue: GitHub.
Appendix: source
Thrown at python/nautilus_trader/analysis/tearsheet.py:2524
heights = [1.0 / rows] * rows
elif num_charts <= _GRID_TWO_ROWS_MAX_CHARTS:
rows, cols = 2, 2
heights = [1.0 / rows] * rows
elif num_charts <= _GRID_THREE_ROWS_MAX_CHARTS:
rows, cols = 3, 2
heights = [1.0 / rows] * rows
else:
cols = 2
rows = max(_GRID_DEFAULT_ROWS, (num_charts + cols - 1) // cols)
heights = (
[0.50, 0.22, 0.16, 0.12] if rows == _GRID_DEFAULT_ROWS else [1.0 / rows] * rows
)
v_spacing = 0.10
h_spacing = 0.10
if len(charts) > rows * cols:
raise ValueError(
f"Grid has {rows * cols} cells but {len(charts)} charts were configured; "
f"provide a larger GridLayout via TearsheetConfig.layout",
)
specs = []
titles = []
chart_idx = 0
for _ in range(rows):
row_specs: list[dict[str, Any] | None] = []
for _ in range(cols):
if chart_idx < len(charts):
chart = charts[chart_idx]
chart_name = chart.name
spec = _TEARSHEET_CHART_SPECS.get(chart_name, {})
subplot_type = spec.get("type", "scatter")
default_title = spec.get("title", chart_name.replace("_", " ").title())View on GitHub (pinned to 18893faf8b)