在python中绘制3D图形时出错

2024-10-04 05:22:49 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d.axes3d import Axes3D

#Read data from file "data.txt" in float format
arregloCompleto=[]
archivo = open("data.txt","r")
while True:
    linea = archivo.readline()
    lineArray = linea.replace("\n","").split(',')
    for i in range(len(lineArray)):
        #Read only numbers
        if(lineArray[i]!= ""):
            arregloCompleto.append(float(lineArray[i]))

    if not linea: break

#Generation X, Y
a = np.mgrid[0:(1271)*0.7142:0.7142]
b = np.mgrid[0:(1015)*0.7142:0.7142]
X, Y = np.meshgrid(a,b)

#Graph 
fig = plt.figure()
ax1 = fig.gca(projection= '3d')
ax1.plot(X,Y,arregloCompleto)
plt.title('Imagen sobre una grafica 3D')
plt.xlabel('Eje x')
plt.ylabel('Eje y')
plt.show()

此代码中的错误是:

^{pr2}$

Tags: infromimporttxtreaddataifas