背景
今日我的Python心路历程是 初探python调试总结之plot方法TypeError: plot() missing 1 required positional argument: ‘ys’))
问题现象
main_var = pca.explained_variance_
plt.plot(main_var[:20])
执行上面代码画图提示错误TypeError: plot() missing 1 required positional argument: 'ys'
。
解决方案
查看源代码也没发现异常,根据经验就看代码上下文,往前看代码中存在跟plt相关的只有针对ax的定义,具体如下:
# 画图
# fig = plt.figure(1, figsize=(4, 3))
# plt.clf()
# ax = Axes3D(fig, rect=[0, 0, .95, 1], elev=48, azim=134)
# plt.cla()
如上所示屏蔽了这些代码后问题解决。