You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用matplotlib绘制ndarray触发TypeError: 'NoneType'不可调用错误求助

问题:Matplotlib绘制ndarray时报错TypeError: 'NoneType' object is not callable

环境信息

  • Python 3.10.4
  • VS Code 1.46.1
  • 依赖库:numpy、matplotlib

代码片段

x = np.arange(0,1,1/fs)
y = float(sig_amp[0:int(fs),200])
import matplotlib.pyplot as plt
plt.plot(x,y)
plt.show()

补充说明:fs=16000.0;x是shape为(16000,)的float64类型ndarray;y原本是shape为(16000,)的int16类型ndarray

报错信息

Traceback (most recent call last):
File "C:\Users\folder.conda\envs\py310\lib\sitepackages\numpy\core\getlimits.py", line 384, 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 "C:\Users\folder.conda\envs\py310\lib\sitepackages\matplotlib\backends\backend_qt.py", line 455, in _draw_idle
self.draw()
File "C:\Users\folder.conda\envs\py310\lib\sitepackages\matplotlib\backends\backend_agg.py", line 436, in draw
self.figure.draw(self.renderer)
File "C:\Users\folder.conda\envs\py310\lib\sitepackages\matplotlib\artist.py", line 73, in draw_wrapper
result = draw(artist, renderer, *args, kwargs)
File "C:\Users\folder.conda\envs\py310\lib\sitepackages\matplotlib\artist.py", line 50, in draw_wrapper
File "C:\Users\folder.conda\envs\py310\lib\sitepackages\matplotlib\figure.py", line 2810, in draw
mimage._draw_list_compositing_images(
a.draw(renderer)
File "C:\Users\folder.conda\envs\py310\lib\sitepackages\matplotlib\artist.py", line 50, in draw_wrapper
File "C:\Users\folder.conda\envs\py310\lib\sitepackages\matplotlib\axes_base.py", line 3020, in draw
self._unstale_viewLim()
File "C:\Users\folder.conda\envs\py310\lib\site-packages\matplotlib\axes_base.py", line 776, in _unstale_viewLim
self.autoscale_view(
{f"scale{name}": scale
handle_single_axis(
File "C:\Users\folder.conda\envs\py310\lib\site-packages\matplotlib\axes_base.py", line 2895, in handle_single_axis
File "C:\Users\folder.conda\envs\py310\lib\site-packages\matplotlib\ticker.py", line 1654, in nonsingular
return mtransforms.nonsingular(v0, v1, expander=.05)
if maxabsvalue < (1e6 / tiny) * np.finfo(float).tiny:
File "C:\Users\folder.conda\envs\py310\lib\site-packages\numpy\core\getlimits.py", line 387, in new
TypeError: 'NoneType' object is not callable

解决方法

  • 核心问题:float()只能转换单个数值,无法直接转换一维数组,你用它处理shape为(16000,)的ndarray会导致y变成无效值,进而触发后续numpy和matplotlib的报错。
  • 修改方案:将y = float(sig_amp[0:int(fs),200])替换为以下任意一种写法:
    1. 转换数组数据类型为float:y = sig_amp[0:int(fs),200].astype(float)
    2. 直接使用原数组(matplotlib支持int16类型的ndarray):y = sig_amp[0:int(fs),200]
  • 验证逻辑:x和y都是长度为16000的一维数组,符合matplotlibplot函数的参数要求,修改后即可正常绘图。

内容的提问来源于stack exchange,提问作者Kinnikuman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 14:05:39