Matplotlib TypeError: 'NoneType'对象不可调用



我已经多次运行此代码,但现在它失败了。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/Numpy?

我对也有同样的问题

  • Python 3.10.4(标签/v3.10.4:9d38122022年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 FilesJetBrainsPyCharm 2022.1pluginspythonhelperspydev_pydevd_bundlepydevd_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模板库来破坏数字模块。(这是一个在错误列表中提出但未解决的问题(

最新更新