{"record":{"id":"f3367b2a5d02fa12","repo":"nautechsystems/nautilus_trader","slug":"grid-has-rows-cols-cells-but-len-charts-cha","errorCode":null,"errorMessage":"Grid has {rows * cols} cells but {len(charts)} charts were configured; provide a larger GridLayout via TearsheetConfig.layout","messagePattern":"Grid has (.+?) cells but (.+?) charts were configured; provide a larger GridLayout via TearsheetConfig\\.layout","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/nautilus_trader/analysis/tearsheet.py","lineNumber":2524,"sourceCode":"            heights = [1.0 / rows] * rows\n        elif num_charts <= _GRID_TWO_ROWS_MAX_CHARTS:\n            rows, cols = 2, 2\n            heights = [1.0 / rows] * rows\n        elif num_charts <= _GRID_THREE_ROWS_MAX_CHARTS:\n            rows, cols = 3, 2\n            heights = [1.0 / rows] * rows\n        else:\n            cols = 2\n            rows = max(_GRID_DEFAULT_ROWS, (num_charts + cols - 1) // cols)\n            heights = (\n                [0.50, 0.22, 0.16, 0.12] if rows == _GRID_DEFAULT_ROWS else [1.0 / rows] * rows\n            )\n\n        v_spacing = 0.10\n        h_spacing = 0.10\n\n    if len(charts) > rows * cols:\n        raise ValueError(\n            f\"Grid has {rows * cols} cells but {len(charts)} charts were configured; \"\n            f\"provide a larger GridLayout via TearsheetConfig.layout\",\n        )\n\n    specs = []\n    titles = []\n    chart_idx = 0\n\n    for _ in range(rows):\n        row_specs: list[dict[str, Any] | None] = []\n\n        for _ in range(cols):\n            if chart_idx < len(charts):\n                chart = charts[chart_idx]\n                chart_name = chart.name\n                spec = _TEARSHEET_CHART_SPECS.get(chart_name, {})\n                subplot_type = spec.get(\"type\", \"scatter\")\n                default_title = spec.get(\"title\", chart_name.replace(\"_\", \" \").title())","sourceCodeStart":2506,"sourceCodeEnd":2542,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/python/nautilus_trader/analysis/tearsheet.py#L2506-L2542","documentation":"_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.","triggerScenarios":"Configuring TearsheetConfig(layout=GridLayout(rows=2, cols=2)) while passing more than 4 TearsheetChart objects to create_tearsheet_from_stats.","commonSituations":"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.","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"],"exampleFix":"// before\ncfg = TearsheetConfig(layout=GridLayout(rows=2, cols=2))  # 5 charts -> ValueError\n// after\ncfg = TearsheetConfig(layout=GridLayout(rows=3, cols=2))  # 6 cells for 5 charts","handlingStrategy":"validation","validationCode":"rows, cols = cfg.layout.rows, cfg.layout.cols\nassert len(charts) <= rows * cols, \\\n    f\"Need {len(charts)} cells, grid has {rows * cols}\"","typeGuard":null,"tryCatchPattern":"try:\n    fig = create_tearsheet_from_stats(stats, config=cfg)\nexcept ValueError as e:\n    if \"cells but\" in str(e):\n        cfg = replace(cfg, layout=auto_sized_layout(len(charts)))\n        fig = create_tearsheet_from_stats(stats, config=cfg)\n    else:\n        raise","preventionTips":["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"],"tags":["python","validation","grid","layout","valueerror"],"backgroundTag":"value-out-of-range","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}