当我运行以下绘图时,控制台总是挂在那里并且绘图永远不会完成。计算量不重,但我不确定哪里不合适。
import matplotlib.pyplot as plt
def showTrajectories(datafilename):
with open(datafilename) as f1:
content1 = f1.readlines()
content1 = [line.strip() for line in content1] # remove newline character
for i in range(int(content1[1])):
traj = [float(x) for x in content1[i+2].split()]
x = traj[2:][::2]
y = traj[2:][1::2]
plt.plot(x, y, color = '#99ffff')
plt.title(datafilename)
plt.xlabel('x (m)', fontsize=16)
plt.ylabel('y (m)', fontsize=16)
plt.show()
def showRepresentatives(resultfilename):
with open(resultfilename) as f2:
content2 = f2.readlines()
content2 = [line.strip() for line in content2] # remove newline character
for i in range(int(content2[0])):
traj = [float(x) for x in content2[i+1].split()]
x = traj[2:][::2]
y = traj[2:][1::2]
plt.plot(x, y, linewidth=3, color='#006633')
plt.title(datafilename)
plt.xlabel('x (m)', fontsize=16)
plt.ylabel('y (m)', fontsize=16)
plt.show()
如果这些很重要,我正在使用适用于 Visual Studio和 Python 2.7的 Python 工具。
showTrajectories(datafilename)
可以正确绘制。它挂起时showRepresentatives(resultfilename)
。所以我将在resultfilename
这里发布数据如下:
10
0 4 -23.6 -2.7 -35.6 -2.1 -47.3 -1.2 -58.0 -1.0
1 6 -56.6 4.5 -58.0 16.7 -59.2 27.4 -60.4 38.8 -61.5 49.5 -62.5 60.1
2 7 -0.6 10.7 -1.5 21.9 -2.6 32.7 -3.6 43.4 -4.7 54.5 -5.6 65.1 -5.8 75.7
3 10 -26.9 73.9 -11.1 75.4 -0.4 75.9 11.9 76.0 22.6 76.0 33.5 76.5 44.2 76.3 55.5 76.2 66.8 77.0 79.3 77.8
4 10 9.2 -8.5 19.1 -14.1 29.6 -16.0 41.4 -16.5 52.2 -16.6 63.0 -16.7 74.1 -15.3 85.8 -12.9 96.5 -13.8 107.0 -15.4
5 8 71.0 -21.0 72.1 -10.4 72.4 0.6 72.2 11.4 72.2 22.7 71.0 33.3 70.0 45.6 70.7 56.5
6 2 72.2 -18.8 79.9 -26.3
7 3 72.6 28.8 86.5 29.4 98.1 30.6
8 5 -60.4 61.2 -71.0 54.2 -81.2 47.0 -90.0 40.9 -99.1 33.3
9 3 73.2 56.2 86.4 58.0 97.7 59.1