{"record":{"id":"96d93761d2afe3f6","repo":"pola-rs/polars","slug":"altair-5-4-0-is-required-for-plot","errorCode":null,"errorMessage":"altair>=5.4.0 is required for `.plot`","messagePattern":"altair>=5\\.4\\.0 is required for `\\.plot`","errorType":"exception","errorClass":"ModuleUpgradeRequiredError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/dataframe/frame.py","lineNumber":766,"sourceCode":"\n        >>> df = pl.DataFrame(\n        ...     {\n        ...         \"day\": [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"] * 2,\n        ...         \"group\": [\"a\"] * 7 + [\"b\"] * 7,\n        ...         \"value\": [1, 3, 2, 4, 5, 6, 1, 1, 3, 2, 4, 5, 1, 2],\n        ...     }\n        ... )\n        >>> df.plot.bar(\n        ...     x=\"day\", y=\"value\", color=\"day\", column=\"group\"\n        ... )  # doctest: +SKIP\n\n        Or, to make a stacked version of the plot above:\n\n        >>> df.plot.bar(x=\"day\", y=\"value\", color=\"group\")  # doctest: +SKIP\n        \"\"\"\n        if not _ALTAIR_AVAILABLE or parse_version(altair.__version__) < (5, 4, 0):\n            msg = \"altair>=5.4.0 is required for `.plot`\"\n            raise ModuleUpgradeRequiredError(msg)\n        return DataFramePlot(self)\n\n    @property\n    @unstable()\n    def style(self) -> GT:\n        \"\"\"\n        Create a Great Table for styling.\n\n        .. warning::\n            This functionality is currently considered **unstable**. It may be\n            changed at any point without it being considered a breaking change.\n\n        Polars does not implement styling logic itself, but instead defers to\n        the Great Tables package. Please see the `Great Tables reference <https://posit-dev.github.io/great-tables/reference/>`_\n        for more information and documentation.\n\n        Examples\n        --------","sourceCodeStart":748,"sourceCodeEnd":784,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/dataframe/frame.py#L748-L784","documentation":"The df.plot accessor requires altair, and specifically version >= 5.4.0 (where the required VegaFusion/plot API surface exists). If the import failed (_ALTAIR_AVAILABLE false) or the installed version parses below (5, 4, 0), polars raises polars.exceptions.ModuleUpgradeRequiredError instead of rendering a broken chart.","triggerScenarios":"df.plot.bar(...), df.plot.point(...), any df.plot.<method> with altair not installed; altair 5.3.x or older pinned in the environment; a fresh venv where altair was listed as optional; altair installed but broken (import error counts as unavailable).","commonSituations":"Docker/CI images built from a requirements.txt that resolved an old altair; upgrading polars without upgrading altair; environments with restricted installs where the viz extra was never added (pip install 'polars[plot]').","solutions":["pip install -U 'altair>=5.4.0'","Add altair to the project's plot extra/environment and rebuild the image/lockfile","If you cannot upgrade, gate plotting behind a version check or use df.to_pandas().plot / great_tables for tabular display"],"exampleFix":"# before (altair 5.3 installed)\ndf.plot.bar(x='a', y='b')  # ModuleUpgradeRequiredError\n\n# after\n# pip install -U 'altair>=5.4.0'\ndf.plot.bar(x='a', y='b')","handlingStrategy":"validation","validationCode":"import importlib.util\n\nspec = importlib.util.find_spec('altair')\nif spec is None:\n    needs_install = True\nelse:\n    import altair\n    needs_install = tuple(int(p) for p in altair.__version__.split('.')[:3]) < (5, 4, 0)\nif needs_install:\n    print('pip install -U \"altair>=5.4.0\"')  # skip plotting path","typeGuard":null,"tryCatchPattern":"from polars.exceptions import ModuleUpgradeRequiredError\n\ntry:\n    chart = df.plot.bar(x='a', y='b')\nexcept ModuleUpgradeRequiredError:\n    chart = df.to_pandas().plot.bar(x='a', y='b')  # degrade gracefully","preventionTips":["Pin 'altair>=5.4.0' in the environment/lockfile wherever .plot is used","Install via the extra: pip install 'polars[plot]'","Gate plotting features behind an availability check in shared notebooks"],"tags":["optional-dependency","altair","plot","version"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}