我需要做一个功能来做到这一点。(顺便说一下Python 3.3)
编写程序 plotEarthquakeData 的合同、文档字符串和实现,该程序需要两个日期,并在世界地图上用点绘制给定日期之间来自 USGS 的所有地震数据。您可以使用 cTurtle 库中的过程点来获取大小和颜色。您可以使用 4 的乘积和点大小的大小,同时使用正确颜色的深度。程序 bgpic 可用于将世界地图图像置于背景中,而程序 setWorldCoordinates 可帮助您更轻松地绘制点。假设整个地图从左到右显示 -180 到 180 度,从下到上显示 -90 到 90 度。
plotEarthquakeData("2013/06/01", "2013/06/04") 应该是这样的
到目前为止我有这个。下面是我已经编写的函数,它们也将在 plotEarthquakeData 函数中使用。
import cTurtle
def plotEarthquakeData(date1,date2):
""" takes two dates and plots all the earthquake data from USGS between the
given dates with dots on the world map."""
myTurtle = cTurtle.Turtle()
myTurtle.bgpic('map.gif')
myTurtle.setWorldCoordinates(-180,-90,180,90)
data = parseEarthquakeData(date1,date2)
for i in range (len(data[1])):
myTurtle.goto(data[0][i], data[1][i])
myturtle.dot(4*data[2][i],colorCode(data[3][1]))
-
def colorCode(depth):
"""takes the depth of an earthquake and returns the corresponding color for
the earthquake."""
if depth<=33:
return "orange"
elif depth<=70:
return "yellow"
elif depth <=150:
return "green"
elif depth<=300:
return "blue"
elif depth <=500:
return "purple"
else:
return "red"
-
import urllib.request
def parseEarthquakeData(date1, date2):
dataFile = urllib.request.urlopen("http://neic.usgs.gov/neis/gis/qed.asc")
latList = []
longList = []
magList = []
depthList = []
count =0
for aline in dataFile:
aline = aline.decode('ascii')
splitData = aline.split(',')
count = count+1
if count>=2:
if (betweenDates (splitData[0],date1,date2)):
latList.append(splitData[2])
longList.append(splitData[3])
magList.append(splitData[4])
depthList.append(splitData[5])
finalList=[]
finalList.append(latList)
finalList.append(longList)
finalList.append(magList)
finalList.append(depthList)
return finalList
当我尝试运行 plotEarthquakeData 时出现此错误,我不知道该怎么做。
plotEarthquakeData("2013/06/01","2013/06/04")
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
plotEarthquakeData("2013/06/01","2013/06/04")
File "C:\Python33\plotEarthquakes.py", line 89, in plotEarthquakeData
myTurtle.goto(data[0][i], data[1][i])
File "C:\Python33\lib\site-packages\cTurtle.py", line 1295, in setpos
self._goto(_Vec(pos, y))
File "C:\Python33\lib\site-packages\cTurtle.py", line 2255, in _goto
diff = end-start
File "C:\Python33\lib\site-packages\cTurtle.py", line 274, in __sub__
return _Vec(self[0]-other[0], self[1]-other[1])
TypeError: unsupported operand type(s) for -: 'str' and 'float'
所以任何帮助试图让我了解我哪里出错了,我们将不胜感激