Unable to plot histogram in pycharm, works fine in terminal (TypeError: 'NoneType' object is not callable)
Unable to plot histogram in pycharm, works fine in terminal (TypeError: 'NoneType' object is not callable)
我在 macOS 终端和 pycharm 控制台中做完全相同的事情:
>>> import matplotlib.pyplot as plt
>>> plt.hist([-94, -89, 88, 55, 45, 44, 43, 42, 1])
2022-05-02 14:04:31.849 Python[2353:66317] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/_0/8cr6pwvs1jg99fgtf2_33lsm0000gn/T/org.python.python.savedState
(array([2., 0., 0., 0., 0., 1., 0., 4., 1., 1.]), array([-94. , -75.8, -57.6, -39.4, -21.2, -3. , 15.2, 33.4, 51.6,
69.8, 88. ]), <BarContainer object of 10 artists>)
>>> plt.show()
import matplotlib.pyplot as plt
plt.hist([-94, -89, 88, 55, 45, 44, 43, 42, 1])
Out[8]:
(array([2., 0., 0., 0., 0., 1., 0., 4., 1., 1.]),
array([-94. , -75.8, -57.6, -39.4, -21.2, -3. , 15.2, 33.4, 51.6,
69.8, 88. ]),
<BarContainer object of 10 artists>)
plt.show()
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/numpy/core/getlimits.py", line 459, in __new__
dtype = numeric.dtype(dtype)
TypeError: 'NoneType' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3251, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-9-1eb00ff78cf2>", line 1, in <module>
plt.show()
File "/usr/local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 368, in show
return _backend_mod.show(*args, **kwargs)
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend/backend_interagg.py", line 29, in __call__
manager.show(**kwargs)
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend/backend_interagg.py", line 112, in show
self.canvas.show()
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend/backend_interagg.py", line 68, in show
FigureCanvasAgg.draw(self)
File "/usr/local/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py", line 436, in draw
self.figure.draw(self.renderer)
File "/usr/local/lib/python3.10/site-packages/matplotlib/artist.py", line 73, in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
return draw(artist, renderer)
File "/usr/local/lib/python3.10/site-packages/matplotlib/figure.py", line 2810, in draw
mimage._draw_list_compositing_images(
File "/usr/local/lib/python3.10/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python3.10/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
return draw(artist, renderer)
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 3020, in draw
self._unstale_viewLim()
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 776, in _unstale_viewLim
self.autoscale_view(**{f"scale{name}": scale
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 2932, in autoscale_view
handle_single_axis(
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 2895, in handle_single_axis
x0, x1 = locator.nonsingular(x0, x1)
File "/usr/local/lib/python3.10/site-packages/matplotlib/ticker.py", line 1654, in nonsingular
return mtransforms.nonsingular(v0, v1, expander=.05)
File "/usr/local/lib/python3.10/site-packages/matplotlib/transforms.py", line 2880, in nonsingular
if maxabsvalue < (1e6 / tiny) * np.finfo(float).tiny:
File "/usr/local/lib/python3.10/site-packages/numpy/core/getlimits.py", line 462, in __new__
dtype = numeric.dtype(type(dtype))
TypeError: 'NoneType' object is not callable
并且都使用相同的解释器
路径
编辑
该错误仅在使用调试器时出现,否则正常。
很可能是 PyCharm 中与 MatplotLib 相关的问题 我会在 PyCharm 问题跟踪器中提出问题:https://youtrack.jetbrains.com/issues/PY
这个问题之前在 Pycharm 社区中讨论过。其中一个有效的方法是降级到 python 3.9。部分版本不兼容。检查 this。您可以查看此线程以获取更多信息。
我在 macOS 终端和 pycharm 控制台中做完全相同的事情:
>>> import matplotlib.pyplot as plt
>>> plt.hist([-94, -89, 88, 55, 45, 44, 43, 42, 1])
2022-05-02 14:04:31.849 Python[2353:66317] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/_0/8cr6pwvs1jg99fgtf2_33lsm0000gn/T/org.python.python.savedState
(array([2., 0., 0., 0., 0., 1., 0., 4., 1., 1.]), array([-94. , -75.8, -57.6, -39.4, -21.2, -3. , 15.2, 33.4, 51.6,
69.8, 88. ]), <BarContainer object of 10 artists>)
>>> plt.show()
import matplotlib.pyplot as plt
plt.hist([-94, -89, 88, 55, 45, 44, 43, 42, 1])
Out[8]:
(array([2., 0., 0., 0., 0., 1., 0., 4., 1., 1.]),
array([-94. , -75.8, -57.6, -39.4, -21.2, -3. , 15.2, 33.4, 51.6,
69.8, 88. ]),
<BarContainer object of 10 artists>)
plt.show()
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/numpy/core/getlimits.py", line 459, in __new__
dtype = numeric.dtype(dtype)
TypeError: 'NoneType' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3251, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-9-1eb00ff78cf2>", line 1, in <module>
plt.show()
File "/usr/local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 368, in show
return _backend_mod.show(*args, **kwargs)
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend/backend_interagg.py", line 29, in __call__
manager.show(**kwargs)
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend/backend_interagg.py", line 112, in show
self.canvas.show()
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend/backend_interagg.py", line 68, in show
FigureCanvasAgg.draw(self)
File "/usr/local/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py", line 436, in draw
self.figure.draw(self.renderer)
File "/usr/local/lib/python3.10/site-packages/matplotlib/artist.py", line 73, in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
return draw(artist, renderer)
File "/usr/local/lib/python3.10/site-packages/matplotlib/figure.py", line 2810, in draw
mimage._draw_list_compositing_images(
File "/usr/local/lib/python3.10/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python3.10/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
return draw(artist, renderer)
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 3020, in draw
self._unstale_viewLim()
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 776, in _unstale_viewLim
self.autoscale_view(**{f"scale{name}": scale
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 2932, in autoscale_view
handle_single_axis(
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 2895, in handle_single_axis
x0, x1 = locator.nonsingular(x0, x1)
File "/usr/local/lib/python3.10/site-packages/matplotlib/ticker.py", line 1654, in nonsingular
return mtransforms.nonsingular(v0, v1, expander=.05)
File "/usr/local/lib/python3.10/site-packages/matplotlib/transforms.py", line 2880, in nonsingular
if maxabsvalue < (1e6 / tiny) * np.finfo(float).tiny:
File "/usr/local/lib/python3.10/site-packages/numpy/core/getlimits.py", line 462, in __new__
dtype = numeric.dtype(type(dtype))
TypeError: 'NoneType' object is not callable
并且都使用相同的解释器
路径
编辑
该错误仅在使用调试器时出现,否则正常。
很可能是 PyCharm 中与 MatplotLib 相关的问题 我会在 PyCharm 问题跟踪器中提出问题:https://youtrack.jetbrains.com/issues/PY
这个问题之前在 Pycharm 社区中讨论过。其中一个有效的方法是降级到 python 3.9。部分版本不兼容。检查 this。您可以查看此线程以获取更多信息。