我正在用Python学习一门课程(我不想让他们解决课程问题或诸如此类的问题),在这一部分中,课程为您提供了一个代码,以便您可以通过图形显示机器人的数量(x轴)和时间步长(y轴),但当我运行代码时,它不会显示任何图形。我该怎么办
抱歉,如果这是一个愚蠢的问题,但我不太擅长python可视化
下面是一些代码:
def showPlot1(title, x_label, y_label):
"""
What information does the plot produced by this function tell you?
"""
num_robot_range = range(1, 11)
times1 = []
times2 = []
for num_robots in num_robot_range:
print("Plotting", num_robots, "robots...")
times1.append(runSimulation(num_robots, 1.0, 20, 20, 0.8, 20, StandardRobot))
times2.append(runSimulation(num_robots, 1.0, 20, 20, 0.8, 20, RandomWalkRobot))
pylab.plot(num_robot_range, times1)
pylab.plot(num_robot_range, times2)
pylab.title(title)
pylab.legend(('StandardRobot', 'RandomWalkRobot'))
pylab.xlabel(x_label)
pylab.ylabel(y_label)
pylab.show()
showPlot1("Title", "Number of robots", "Time-steps")
下面是它显示的内容:
下面是它打印的内容:
Plotting 1 robots...
801.95
2019.15
Plotting 2 robots...
387.35
997.35
Plotting 3 robots...
256.4
732.7
Plotting 4 robots...
201.3
430.2
Plotting 5 robots...
158.25
366.3
Plotting 6 robots...
133.15
328.0
Plotting 7 robots...
113.65
276.1
Plotting 8 robots...
100.0
239.9
Plotting 9 robots...
85.9
191.85
Plotting 10 robots...
78.1
162.3
谢谢你的帮助
我写了一个虚拟的
runSimulation
而且,使用你发布的
showPlot1
,我得到了一个完美的情节然后我从我的伪代码中删除了
return result
语句,这就是我得到的(注意轴的限制,与图中相同)我的结论是,您的
return something
版本中没有相应的runSimulation
-请检查您的代码,并让我们知道我的猜测是否正确相关问题 更多 >
编程相关推荐