Skip to content

[Bug]: Import Error in Matplotlib 3.5.1 #22305

Closed

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

Activity

  1. added this to the v3.5.2 milestone on Jan 24, 2022
  2. added 3 commits that reference this issue on Jan 24, 2022
    8704345
    b512c70
    07f7ec6
  3. added a commit that references this issue on Jan 26, 2022
    df85ec0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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