matplotlib show()接受1个位置参数,但给出了2个

wnrlj8wa  于 2023-05-07  发布在  其他
关注(0)|答案(2)|浏览(223)

我得到了一些关于我一直在工作的代码的很好的反馈,并且我已经在Google collab上运行了所有内容,但是当我在Visual Studio上运行完全相同的代码时,我得到的错误是这样的:
发生异常:TypeError show()接受1个位置参数,但给出了2个
下面是我的代码:

import pandas as pd
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt

            
def run_analytics(data):
  for i in set(data['MovementNumber'].values):
    print("Plot for Movement Number " + str(i))
    data2 = data.loc[data['MovementNumber'] == i]
    ax = plt.axes(projection='3d')
    xdata = data2['PlayerPosX'].values
    ydata = data2['PlayerPosY'].values
    zdata = data2['PlayerPosZ'].values
    len(xdata)
    plot1 = ax.scatter3D(xdata[:,1], ydata, zdata, c=zdata)
    plt.show(plot1)

if __name__ == "__main__":
  data = pd.read_csv('Assetslog_912021_11.csv')
  data.columns = ['Time', 'Fixed Delta', 'Movement Time', 'MovementNumber', 'MovementDir', 'Rest Flag', 'DistortionDigit', 'RobotForceX','RobotForceY','RobotForceZ', 'PrevPositionX','PrevPositionY','PrevPositionZ', 'TargetPosX', 'TargetPosY', 'TargetPosZ', 'PlayerPosX', 'PlayerPosX', 'PlayerPosY', 'PlayerPosZ', 'RobotVelX','RobotVelY','RobotVelZ', 'LocalPosX', 'LocalPosY', 'LocalPosZ', 'PerpError' ]  
  data['RobotForce'] = data[['RobotForceX', 'RobotForceY', 'RobotForceZ']].values.tolist()
  data['StartPos'] = data[['PrevPositionX', 'PrevPositionY', 'PrevPositionZ']].values.tolist()
  data['TargetPos'] = data[['TargetPosX', 'TargetPosY', 'TargetPosZ']].values.tolist()
  data['PlayerPos'] = data[['PlayerPosX', 'PlayerPosY', 'PlayerPosZ']].values.tolist()
  data['RobotVel'] = data[['RobotVelX', 'RobotVelY', 'RobotVelZ']].values.tolist()
  run_analytics(data)

我知道它可以优化得更多,但现在我不太担心那部分。我知道我需要补充这一点:

class MyClass():
      
  def __init__(self,show):
    self.plot1 = plot1 
    self.data = data
    self.run_analytics = run_analytics

但我认为我没有正确地称呼自己。有人能给我解释一下吗?

h6my8fg2

h6my8fg21#

不需要这个均衡器

plot1 = ax.scatter3D(xdata[:,1], ydata, zdata, c=zdata)

你必须这样改变:

ax.scatter3D(xdata[:,1], ydata, zdata, c=zdata)
plt.show()
ie3xauqp

ie3xauqp2#

show()函数不接受参数:

import pandas as pd
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt

            
def run_analytics(data):
  for i in set(data['MovementNumber'].values):
    print("Plot for Movement Number " + str(i))
    data2 = data.loc[data['MovementNumber'] == i]
    ax = plt.axes(projection='3d')
    xdata = data2['PlayerPosX'].values
    ydata = data2['PlayerPosY'].values
    zdata = data2['PlayerPosZ'].values
    len(xdata)
    plot1 = ax.scatter3D(xdata[:,1], ydata, zdata, c=zdata)
    plt.show()

if __name__ == "__main__":
  data = pd.read_csv('Assetslog_912021_11.csv')
  data.columns = ['Time', 'Fixed Delta', 'Movement Time', 'MovementNumber', 'MovementDir', 'Rest Flag', 'DistortionDigit', 'RobotForceX','RobotForceY','RobotForceZ', 'PrevPositionX','PrevPositionY','PrevPositionZ', 'TargetPosX', 'TargetPosY', 'TargetPosZ', 'PlayerPosX', 'PlayerPosX', 'PlayerPosY', 'PlayerPosZ', 'RobotVelX','RobotVelY','RobotVelZ', 'LocalPosX', 'LocalPosY', 'LocalPosZ', 'PerpError' ]  
  data['RobotForce'] = data[['RobotForceX', 'RobotForceY', 'RobotForceZ']].values.tolist()
  data['StartPos'] = data[['PrevPositionX', 'PrevPositionY', 'PrevPositionZ']].values.tolist()
  data['TargetPos'] = data[['TargetPosX', 'TargetPosY', 'TargetPosZ']].values.tolist()
  data['PlayerPos'] = data[['PlayerPosX', 'PlayerPosY', 'PlayerPosZ']].values.tolist()
  data['RobotVel'] = data[['RobotVelX', 'RobotVelY', 'RobotVelZ']].values.tolist()
  run_analytics(data)

相关问题