{"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":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/nautilus_trader/analysis/tearsheet.py","lineNumber":2526,"sourceCode":"        if num_charts <= 2:\n            rows, cols = 1, num_charts\n            heights = [1.0 / rows] * rows\n        elif num_charts <= 4:\n            rows, cols = 2, 2\n            heights = [1.0 / rows] * rows\n        elif num_charts <= 6:\n            rows, cols = 3, 2\n            heights = [1.0 / rows] * rows\n        else:\n            cols = 2\n            rows = max(4, (num_charts + cols - 1) // cols)\n            heights = [0.50, 0.22, 0.16, 0.12] if rows == 4 else [1.0 / rows] * rows\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":2508,"sourceCodeEnd":2544,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/python/nautilus_trader/analysis/tearsheet.py#L2508-L2544","documentation":"_calculate_grid_layout checks that the chosen subplot grid can hold every configured chart: len(charts) must be <= rows*cols. With a custom TearsheetConfig.layout (a plotly GridLayout) the grid dimensions are user-supplied, so an under-sized layout is rejected instead of silently dropping charts.","triggerScenarios":"Passing TearsheetConfig(layout=GridLayout with e.g. 2x2=4 cells) together with 5+ charts in config.charts; or a custom layout whose row/col product is smaller than the charts list even when auto-layout would have sufficed.","commonSituations":"Hand-tuning a tearsheet layout then adding more charts later; copying a layout sized for the default chart set into a config that appends custom charts.","solutions":["Enlarge the custom layout (more rows/cols) so rows*cols >= len(config.charts)","Or remove charts from TearsheetConfig.charts until they fit","Or drop the custom layout (layout=None) to let the function auto-size rows/cols for any chart count"],"exampleFix":"# before\nlayout = GridLayout(grid=[[{'colspan': 2}, None], [{}, {}]])  # 4 cells\nconfig = TearsheetConfig(charts=[c1, c2, c3, c4, c5], layout=layout)\n# ValueError: Grid has 4 cells but 5 charts were configured\n\n# after\nlayout = GridLayout(grid=[[{'colspan': 2}, None], [{}, {}], [{}, {}]])  # 6 cells\nconfig = TearsheetConfig(charts=[c1, c2, c3, c4, c5], layout=layout)","handlingStrategy":"validation","validationCode":"if config.layout is not None:\n    cells = config.layout.rows * config.layout.cols  # adapt to your GridLayout accessor\n    assert len(config.charts) <= cells, (\n        f'{len(config.charts)} charts > {cells} grid cells; enlarge layout or trim charts'\n    )\ncreate_tearsheet(returns=result, config=config)","typeGuard":null,"tryCatchPattern":"try:\n    create_tearsheet(returns=result, config=config)\nexcept ValueError as e:\n    if 'Grid has' in str(e):\n        config = TearsheetConfig(charts=config.charts, layout=None)  # auto-size\n        create_tearsheet(returns=result, config=config)\n    else:\n        raise","preventionTips":["Prefer layout=None (auto) unless hand-tuning is required","When appending charts in code, recompute required cells: rows = ceil(n / cols)","Add a config unit test asserting len(charts) <= rows*cols for your shipped layout"],"tags":["python","tearsheet","layout","grid-capacity","config-validation"],"backgroundTag":"layout-capacity-exceeded","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}