1
1
# -----------------------------------------------------------------------------
2
- # Copyright (c) 2015 , Nicolas P. Rougier. All Rights Reserved.
2
+ # Copyright (c) 2014 , Nicolas P. Rougier. All Rights Reserved.
3
3
# Distributed under the (new) BSD License.
4
4
# -----------------------------------------------------------------------------
5
5
# Based on : https://peak5390.wordpress.com
23
23
# url = urllib.urlopen(feed + "significant_month.csv")
24
24
25
25
# Earthquakes of magnitude > 4.5 in the past 30 days
26
- url = urllib .urlopen (feed + "4.5_month.csv" )
26
+ url = urllib .request . urlopen (feed + "4.5_month.csv" )
27
27
28
28
# Earthquakes of magnitude > 2.5 in the past 30 days
29
29
# url = urllib.urlopen(feed + "2.5_month.csv")
32
32
# url = urllib.urlopen(feed + "1.0_month.csv")
33
33
34
34
# Set earthquake data
35
- data = url .read ().split ('\n ' )[+ 1 :- 1 ]
35
+ data = url .read ()
36
+ data = data .split (b'\n ' )[+ 1 :- 1 ]
36
37
E = np .zeros (len (data ), dtype = [('position' , float , 2 ),
37
38
('magnitude' , float , 1 )])
38
39
for i in range (len (data )):
39
- row = data [i ].split (',' )
40
+ row = data [i ].split (b ',' )
40
41
E ['position' ][i ] = float (row [2 ]),float (row [1 ])
41
42
E ['magnitude' ][i ] = float (row [4 ])
42
43
43
44
44
- fig = plt .figure (figsize = (10 , 8 ))
45
+ fig = plt .figure (figsize = (14 , 10 ))
45
46
ax = plt .subplot (1 ,1 ,1 )
46
47
P = np .zeros (50 , dtype = [('position' , float , 2 ),
47
48
('size' , float , 1 ),
48
49
('growth' , float , 1 ),
49
50
('color' , float , 4 )])
50
51
51
52
# Basemap projection
52
- earth = Basemap (projection = 'mill' )
53
- earth .drawcoastlines (color = '0.50' , linewidth = 0.25 )
54
- earth .fillcontinents (color = '0.95' )
53
+ map = Basemap (projection = 'mill' )
54
+ map .drawcoastlines (color = '0.50' , linewidth = 0.25 )
55
+ map .fillcontinents (color = '0.95' )
55
56
scat = ax .scatter (P ['position' ][:,0 ], P ['position' ][:,1 ], P ['size' ], lw = 0.5 ,
56
57
edgecolors = P ['color' ], facecolors = 'None' , zorder = 10 )
57
58
@@ -64,7 +65,7 @@ def update(frame):
64
65
P ['size' ] += P ['growth' ]
65
66
66
67
magnitude = E ['magnitude' ][current ]
67
- P ['position' ][i ] = earth (* E ['position' ][current ])
68
+ P ['position' ][i ] = map (* E ['position' ][current ])
68
69
P ['size' ][i ] = 5
69
70
P ['growth' ][i ]= np .exp (magnitude ) * 0.1
70
71
@@ -76,9 +77,7 @@ def update(frame):
76
77
scat .set_facecolors (P ['color' ]* (1 ,1 ,1 ,0.25 ))
77
78
scat .set_sizes (P ['size' ])
78
79
scat .set_offsets (P ['position' ])
79
- return scat ,
80
80
81
-
82
- plt .title ("Earthquakes > 4.5 in the last 30 days (18/08/2015)" )
81
+ plt .title ("Earthquakes > 4.5 in the last 30 days" )
83
82
animation = FuncAnimation (fig , update , interval = 10 )
84
83
plt .show ()
0 commit comments