无法在pycharm中绘制直方图,在终端中工作正常

xkftehaa  于 2022-11-08  发布在  PyCharm
关注(0)|答案(2)|浏览(197)

我在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

而且两者都使用相同的解释器

路径

编辑

只有在使用调试器时才会发生此错误,否则调试器工作正常。

kcugc4gi

kcugc4gi1#

很可能是PyCharm中与MatplotLib相关的问题,我会在PyCharm问题跟踪器中提出一个问题:https://youtrack.jetbrains.com/issues/PY

a64a0gku

a64a0gku2#

这个问题之前在Pycharm社区讨论过。其中一个有效的方法是降级到python 3.9。一些版本不兼容。检查this。你可以检查这个线程以获得更多信息。

相关问题