我对编程很陌生,希望能对我的程序提供一些帮助。我正在尝试通过 for 循环读取数组,对它们进行一些计算并将结果绘制在 3D 图上,但它给了我错误:
IndexError: index 753 is out of bounds for axis 0 with size 753
这是代码:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import math
from itertools import product, combinations
from numpy import *
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect("equal")
ra_day = loadtxt("RA Days.txt")
ra_minute = loadtxt("RA Minutes.txt")
ra_second = loadtxt("RA Seconds.txt")
ra = ra_day + (ra_minute/60) + (ra_second/3600)
dec_day = loadtxt("DEC Days.txt")
dec_minute = loadtxt("DEC Minutes.txt")
dec_second = loadtxt("DEC Seconds.txt")
dec = dec_day + (dec_minute/60) + (dec_second/3600)
dist = loadtxt("Distance.txt")
for i in range(len(ra)):
x = math.cos(ra[i]) * (dist[i] * math.cos(dec[i]))
y = math.sin(ra[i]) * (dist[i] * math.cos(dec[i]))
z = dist * math.sin(dec[i])
ax.scatter([0],[0],[0],color="b",s=100)
ax.scatter([x],[y],[z],color="k",s=100)
plt.show()