TypeError: 'tuple' object is not callable when trying to subplot in python
TypeError: 'tuple' object is not callable when trying to subplot in python
目前正在尝试在 python 中制作一些子图。这个确切的代码昨天有效,现在我得到 "TypeError: 'tuple' object is not callable"
奇怪的是它让我在命令栏中单独 运行 所有这些图表,但是当我 运行 完整代码时它只绘制了其中两个然后给我这个错误。我必须重新启动内核才能再次开始绘图,否则我尝试绘制的任何东西都会给我那个答案。
这是我要编写的代码:
plt.subplot(2,2,1)
plt.plot(x_axis, avg_ANK_ang[:,0], color='red', linewidth=1, linestyle = '--')
plt.fill_between(x_axis, avg_ANK_ang[:,0]-angANKnvf_err, avg_ANK_ang[:,0]+angANKnvf_err, alpha=0.5, facecolor='#FF9848')
plt.plot(x_axis, avg_ANK_ang[:,1], color='blue', linewidth=1)
plt.fill_between(x_axis, avg_ANK_ang[:,1]-angANKcvf_err, avg_ANK_ang[:,1]+angANKcvf_err, alpha=0.5, facecolor='#089FFF')
plt.xticks([])
seaborn.despine(left=True, bottom=True, right=True)
plt.ylabel("Ankle")
plt.title("Angle (deg)")
plt.subplot(2,2,3)
plt.plot(x_axis, avg_MTP_ang[:,0], color='red', linewidth=1, linestyle = '--')
plt.fill_between(x_axis, avg_MTP_ang[:,0]-angMTPnvf_err, avg_MTP_ang[:,0]+angMTPnvf_err, alpha=0.5, facecolor='#FF9848')
plt.plot(x_axis, avg_MTP_ang[:,1], color='blue', linewidth=1)
plt.fill_between(x_axis, avg_MTP_ang[:,1]-angMTPcvf_err, avg_MTP_ang[:,1]+angMTPcvf_err, alpha=0.5, facecolor='#089FFF')
seaborn.despine(left=True, bottom=True, right=True)
plt.plot = (x_axis, 0)
plt.ylabel("MTP")
plt.xlabel("% stance")
plt.subplot(2,2,2)
plt.plot(x_axis, avg_ANK_mom[:,0], color='red', linewidth=1, linestyle = '--')
plt.fill_between(x_axis, avg_ANK_mom[:,0]-momANKnvf_err, avg_ANK_mom[:,0]+momANKnvf_err, alpha=0.5, facecolor='#FF9848')
plt.plot(x_axis, avg_ANK_mom[:,1], color='blue', linewidth=1)
plt.fill_between(x_axis, avg_ANK_mom[:,1]-momANKcvf_err, avg_ANK_mom[:,1]+momANKcvf_err, alpha=0.5, facecolor='#089FFF')
plt.xticks([])
seaborn.despine(left=True, bottom=True, right=True)
plt.title("Moment (NM)")
plt.subplot(2,2,4)
plt.plot(x_axis, avg_MTP_mom[:,0], color='red', linewidth=1, linestyle = '--')
plt.fill_between(x_axis, avg_MTP_mom[:,0]-momMTPnvf_err, avg_MTP_mom[:,0]+momMTPnvf_err, alpha=0.5, facecolor='#FF9848')
plt.plot(x_axis, avg_MTP_mom[:,1], color='blue', linewidth=1)
plt.fill_between(x_axis, avg_MTP_mom[:,1]-momMTPcvf_err, avg_MTP_mom[:,1]+momMTPcvf_err, alpha=0.5, facecolor='#089FFF')
seaborn.despine(left=True, bottom=True, right=True)
plt.xlabel("% stance")
错误:
File "/Users/Laura/Box/NVF/Biomechanics data/Compile/compile.py", line 130, in <module>
plt.plot(x_axis, avg_ANK_mom[:,0], color='red', linewidth=1, linestyle = '--')
TypeError: 'tuple' object is not callable
另一件奇怪的事情是它通常在给出错误之前绘制前两个图。 (除非我将它们单独放在命令window中,否则通常会绘制前三个)
plt.plot = (x_axis, 0)
那行代码就是问题所在。您已将 plt.plot
重新分配为一个元组变量,它不再是一个函数。
目前正在尝试在 python 中制作一些子图。这个确切的代码昨天有效,现在我得到 "TypeError: 'tuple' object is not callable"
奇怪的是它让我在命令栏中单独 运行 所有这些图表,但是当我 运行 完整代码时它只绘制了其中两个然后给我这个错误。我必须重新启动内核才能再次开始绘图,否则我尝试绘制的任何东西都会给我那个答案。
这是我要编写的代码:
plt.subplot(2,2,1)
plt.plot(x_axis, avg_ANK_ang[:,0], color='red', linewidth=1, linestyle = '--')
plt.fill_between(x_axis, avg_ANK_ang[:,0]-angANKnvf_err, avg_ANK_ang[:,0]+angANKnvf_err, alpha=0.5, facecolor='#FF9848')
plt.plot(x_axis, avg_ANK_ang[:,1], color='blue', linewidth=1)
plt.fill_between(x_axis, avg_ANK_ang[:,1]-angANKcvf_err, avg_ANK_ang[:,1]+angANKcvf_err, alpha=0.5, facecolor='#089FFF')
plt.xticks([])
seaborn.despine(left=True, bottom=True, right=True)
plt.ylabel("Ankle")
plt.title("Angle (deg)")
plt.subplot(2,2,3)
plt.plot(x_axis, avg_MTP_ang[:,0], color='red', linewidth=1, linestyle = '--')
plt.fill_between(x_axis, avg_MTP_ang[:,0]-angMTPnvf_err, avg_MTP_ang[:,0]+angMTPnvf_err, alpha=0.5, facecolor='#FF9848')
plt.plot(x_axis, avg_MTP_ang[:,1], color='blue', linewidth=1)
plt.fill_between(x_axis, avg_MTP_ang[:,1]-angMTPcvf_err, avg_MTP_ang[:,1]+angMTPcvf_err, alpha=0.5, facecolor='#089FFF')
seaborn.despine(left=True, bottom=True, right=True)
plt.plot = (x_axis, 0)
plt.ylabel("MTP")
plt.xlabel("% stance")
plt.subplot(2,2,2)
plt.plot(x_axis, avg_ANK_mom[:,0], color='red', linewidth=1, linestyle = '--')
plt.fill_between(x_axis, avg_ANK_mom[:,0]-momANKnvf_err, avg_ANK_mom[:,0]+momANKnvf_err, alpha=0.5, facecolor='#FF9848')
plt.plot(x_axis, avg_ANK_mom[:,1], color='blue', linewidth=1)
plt.fill_between(x_axis, avg_ANK_mom[:,1]-momANKcvf_err, avg_ANK_mom[:,1]+momANKcvf_err, alpha=0.5, facecolor='#089FFF')
plt.xticks([])
seaborn.despine(left=True, bottom=True, right=True)
plt.title("Moment (NM)")
plt.subplot(2,2,4)
plt.plot(x_axis, avg_MTP_mom[:,0], color='red', linewidth=1, linestyle = '--')
plt.fill_between(x_axis, avg_MTP_mom[:,0]-momMTPnvf_err, avg_MTP_mom[:,0]+momMTPnvf_err, alpha=0.5, facecolor='#FF9848')
plt.plot(x_axis, avg_MTP_mom[:,1], color='blue', linewidth=1)
plt.fill_between(x_axis, avg_MTP_mom[:,1]-momMTPcvf_err, avg_MTP_mom[:,1]+momMTPcvf_err, alpha=0.5, facecolor='#089FFF')
seaborn.despine(left=True, bottom=True, right=True)
plt.xlabel("% stance")
错误:
File "/Users/Laura/Box/NVF/Biomechanics data/Compile/compile.py", line 130, in <module>
plt.plot(x_axis, avg_ANK_mom[:,0], color='red', linewidth=1, linestyle = '--')
TypeError: 'tuple' object is not callable
另一件奇怪的事情是它通常在给出错误之前绘制前两个图。 (除非我将它们单独放在命令window中,否则通常会绘制前三个)
plt.plot = (x_axis, 0)
那行代码就是问题所在。您已将 plt.plot
重新分配为一个元组变量,它不再是一个函数。