Matplotlib TypeError:“NoneType”对象不可调用

问题描述 投票:0回答:2

我已经多次运行此代码,但现在失败了。 Matplotlib 不适用于任何示例,即使是最微不足道的示例。这是我遇到的错误,但我不知道该怎么办。我知道这是模糊的,我无法真正提供重现它的方法。我已经卸载了最近安装的每个软件包并尝试重新安装 matplotlib。

fig = plt.figure()
        ax = fig.add_subplot(1, 1, 1)
        plt.plot(self.I_hist)
        plt.show()
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/backends/backend_macosx.py", line 41, in _draw
    self.figure.draw(renderer)
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/artist.py", line 73, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
    return draw(artist, renderer)
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/figure.py", line 2810, in draw
    mimage._draw_list_compositing_images(
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
    return draw(artist, renderer)
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 3020, in draw
    self._unstale_viewLim()
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 776, in _unstale_viewLim
    self.autoscale_view(**{f"scale{name}": scale
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 2932, in autoscale_view
    handle_single_axis(
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 2895, in handle_single_axis
    x0, x1 = locator.nonsingular(x0, x1)
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/ticker.py", line 1654, in nonsingular
    return mtransforms.nonsingular(v0, v1, expander=.05)
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/transforms.py", line 2880, in nonsingular
    if maxabsvalue < (1e6 / tiny) * np.finfo(float).tiny:
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/numpy/core/getlimits.py", line 462, in __new__
    dtype = numeric.dtype(type(dtype))
TypeError: 'NoneType' object is not callable
python matplotlib data-visualization
2个回答
6
投票

您使用什么版本的 Python/Numpy?

我也有同样的问题

  • Python 3.10.4(tags/v3.10.4:9d38120,2022 年 3 月 23 日,23:13:41)[MSC v.1929 64 位 (AMD64)] 在 win32 上

  • numpy==1.22.3

  • PyCharm 2022.1(专业版)

>>> from numpy.core import numeric
>>> numeric.dtype(float)

numeric.dtype(float)
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2022.1\plugins\python\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
TypeError: 'NoneType' object is not callable

显然 numeric.dtype 没有正确定义。 (其值为 None!) 如果你使用 np.dtype(float) 就可以了。

>>> import numpy as np
>>> np.dtype(float)

dtype('float64')

我相信,如果您在 PyCharm 中关闭科学模式,这应该会再次起作用。

设置->工具->Python Scientific,取消选中 在工具窗口中显示绘图

显然 Jetbrains 使用了一个空的 numpy.core 模板库,这破坏了 numeric 模块。 (这是错误列表中提出但未解决的问题)


0
投票

我只在 ipython 和 pdb 上遇到这个问题。对我来说,问题似乎是 pandas.read_csv() 将 numpy.core.numeric.dtype 更改为 None。

© www.soinside.com 2019 - 2024. All rights reserved.