diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 00d87b707580dc..302d5ede0ae863 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -7,8 +7,6 @@ Sequence, ) -import pkg_resources - from pandas._config import get_option from pandas._typing import IndexLabel @@ -1745,6 +1743,8 @@ def _load_backend(backend: str) -> types.ModuleType: types.ModuleType The imported backend. """ + import pkg_resources + if backend == "matplotlib": # Because matplotlib is an optional dependency and first-party backend, # we need to attempt an import here to raise an ImportError if needed.