Skip to content

[Bug]: Import Error in Matplotlib 3.5.1 #22305

Closed
@skuschel

Description

@skuschel

Bug summary

Cannot create a matplotlib.ticker.ScalarFormatter() without importing "unnecessary" imports.

Code for reproduction

import matplotlib
print(matplotlib.__version__)
import matplotlib.ticker
matplotlib.ticker.ScalarFormatter()


### Actual outcome

```---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [1], in <module>
      2 print(matplotlib.__version__)
      3 import matplotlib.ticker
----> 4 matplotlib.ticker.ScalarFormatter()

File /usr/lib/python3.10/site-packages/matplotlib/ticker.py:444, in ScalarFormatter.__init__(self, useOffset, useMathText, useLocale)
    442 if useMathText is False:
    443     try:
--> 444         ufont = mpl.font_manager.findfont(
    445             mpl.font_manager.FontProperties(
    446                 mpl.rcParams["font.family"]
    447             ),
    448             fallback_to_default=False,
    449         )
    450     except ValueError:
    451         ufont = None

File /usr/lib/python3.10/site-packages/matplotlib/_api/__init__.py:222, in caching_module_getattr.<locals>.__getattr__(name)
    220 if name in props:
    221     return props[name].__get__(instance)
--> 222 raise AttributeError(
    223     f"module {cls.__module__!r} has no attribute {name!r}")

AttributeError: module 'matplotlib' has no attribute 'font_manager'

Expected outcome

should run without error as in previous versions.

Additional information

As a workaround just execute the following command before creating the ScalarFormatter

import matplotlib.font_manager

Operating system

Arch Linux

Matplotlib Version

3.5.1

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.10.2

Jupyter version

3.2.8 (dev), 3.0.16 (app)

Installation

Linux package manager

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions