import numpy as np
#import blaze as bl
import pandas as pd
import seaborn; seaborn.set()
from matplotlib import pyplot as plt
import time
%matplotlib inline
uri = 'http://www.ldeo.columbia.edu/~rpa/usgs_earthquakes_2014.csv'
d = pd.read_csv(uri, parse_dates = ['time',], index_col='time')
d.head()
latitude | longitude | depth | mag | magType | nst | gap | dmin | rms | net | id | updated | place | type | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
time | ||||||||||||||
2014-01-31 23:53:37.000 | 60.252000 | -152.7081 | 90.20 | 1.10 | ml | NaN | NaN | NaN | 0.2900 | ak | ak11155107 | 2014-02-05T19:34:41.515Z | 26km S of Redoubt Volcano, Alaska | earthquake |
2014-01-31 23:48:35.452 | 37.070300 | -115.1309 | 0.00 | 1.33 | ml | 4 | 171.43 | 0.34200 | 0.0247 | nn | nn00436847 | 2014-02-01T01:35:09.000Z | 32km S of Alamo, Nevada | earthquake |
2014-01-31 23:47:24.000 | 64.671700 | -149.2528 | 7.10 | 1.30 | ml | NaN | NaN | NaN | 1.0000 | ak | ak11151142 | 2014-02-01T00:03:53.010Z | 12km NNW of North Nenana, Alaska | earthquake |
2014-01-31 23:30:54.000 | 63.188700 | -148.9575 | 96.50 | 0.80 | ml | NaN | NaN | NaN | 1.0700 | ak | ak11151135 | 2014-01-31T23:41:25.007Z | 22km S of Cantwell, Alaska | earthquake |
2014-01-31 23:30:52.210 | 32.616833 | -115.6925 | 10.59 | 1.34 | ml | 6 | 285.00 | 0.04321 | 0.2000 | ci | ci37171541 | 2014-02-01T00:13:20.107Z | 10km WNW of Progreso, Mexico | earthquake |
d.describe()
latitude | longitude | depth | mag | nst | gap | dmin | rms | |
---|---|---|---|---|---|---|---|---|
count | 120108.000000 | 120108.000000 | 120107.000000 | 120065.000000 | 59688.000000 | 94935.000000 | 85682.000000 | 119716.000000 |
mean | 38.399579 | -99.961402 | 28.375029 | 1.793958 | 17.878284 | 124.048978 | 0.893198 | 0.358174 |
std | 21.938258 | 82.996858 | 62.215416 | 1.343466 | 14.911369 | 68.518595 | 2.903966 | 0.364046 |
min | -73.462000 | -179.998900 | -9.900000 | -0.970000 | 0.000000 | 9.000000 | 0.000000 | 0.000000 |
25% | 34.228917 | -147.742025 | 4.100000 | 0.820000 | 8.000000 | 74.000000 | 0.020760 | 0.070000 |
50% | 38.805300 | -120.832000 | 9.200000 | 1.400000 | 14.000000 | 107.000000 | 0.073670 | 0.200000 |
75% | 53.889500 | -116.068100 | 22.880000 | 2.400000 | 22.000000 | 155.000000 | 0.447000 | 0.590000 |
max | 86.651400 | 179.998000 | 697.360000 | 8.200000 | 365.000000 | 356.400000 | 64.498000 | 8.460000 |
top = d.sort('mag', ascending=False).head(20)
top
latitude | longitude | depth | mag | magType | nst | gap | dmin | rms | net | id | updated | place | type | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
time | ||||||||||||||
2014-04-01 23:46:47.260 | -19.6097 | -70.7691 | 25.00 | 8.2 | mww | NaN | 23 | 0.609 | 0.66 | us | usc000nzvd | 2015-07-30T16:24:51.223Z | 94km NW of Iquique, Chile | earthquake |
2014-06-23 20:53:09.700 | 51.8486 | 178.7352 | 109.00 | 7.9 | mww | NaN | 22 | 0.133 | 0.71 | us | usc000rki5 | 2015-04-18T21:54:08.699Z | 19km SE of Little Sitkin Island, Alaska | earthquake |
2014-04-03 02:43:13.110 | -20.5709 | -70.4931 | 22.40 | 7.7 | mww | NaN | 44 | 1.029 | 0.82 | us | usc000p27i | 2015-06-06T07:31:05.755Z | 53km SW of Iquique, Chile | earthquake |
2014-04-12 20:14:39.300 | -11.2701 | 162.1481 | 22.56 | 7.6 | mww | NaN | 13 | 2.828 | 0.71 | us | usc000phx5 | 2015-04-18T21:54:27.398Z | 93km SSE of Kirakira, Solomon Islands | earthquake |
2014-04-19 13:28:00.810 | -6.7547 | 155.0241 | 43.37 | 7.5 | mww | NaN | 16 | 3.820 | 1.25 | us | usb000pr89 | 2015-04-18T21:54:18.633Z | 70km SW of Panguna, Papua New Guinea | earthquake |
2014-04-13 12:36:19.230 | -11.4633 | 162.0511 | 39.00 | 7.4 | mww | NaN | 17 | 2.885 | 1.00 | us | usc000piqj | 2015-08-13T19:29:13.018Z | 112km S of Kirakira, Solomon Islands | earthquake |
2014-10-14 03:51:34.460 | 12.5262 | -88.1225 | 40.00 | 7.3 | mww | NaN | 18 | 1.078 | 0.70 | us | usb000slwn | 2015-08-13T19:35:02.679Z | 74km S of Intipuca, El Salvador | earthquake |
2014-04-18 14:27:24.920 | 17.3970 | -100.9723 | 24.00 | 7.2 | mww | NaN | 46 | 2.250 | 1.20 | us | usb000pq41 | 2015-08-13T19:30:39.599Z | 33km ESE of Petatlan, Mexico | earthquake |
2014-04-11 07:07:23.130 | -6.5858 | 155.0485 | 60.53 | 7.1 | mww | NaN | 21 | 3.729 | 0.88 | us | usc000pft9 | 2014-07-01T02:37:56.000Z | 56km WSW of Panguna, Papua New Guinea | earthquake |
2014-11-15 02:31:41.720 | 1.8929 | 126.5217 | 45.00 | 7.1 | mww | NaN | 18 | 1.397 | 0.71 | us | usc000sxh8 | 2015-03-20T18:42:02.735Z | 154km NW of Kota Ternate, Indonesia | earthquake |
2014-11-01 18:57:22.380 | -19.6903 | -177.7587 | 434.00 | 7.1 | mww | NaN | 13 | 4.415 | 0.84 | us | usc000stdc | 2015-01-20T09:03:09.040Z | 144km NE of Ndoi Island, Fiji | earthquake |
2014-10-09 02:14:31.440 | -32.1082 | -110.8112 | 16.54 | 7.0 | mww | NaN | 22 | 5.127 | 0.43 | us | usb000sk6k | 2015-08-13T19:31:44.129Z | Southern East Pacific Rise | earthquake |
2014-06-29 07:52:55.170 | -55.4703 | -28.3669 | 8.00 | 6.9 | mww | NaN | 25 | 4.838 | 0.76 | us | usc000rngj | 2014-09-26T11:49:45.000Z | 154km NNW of Visokoi Island, | earthquake |
2014-08-03 00:22:03.680 | 0.8295 | 146.1688 | 13.00 | 6.9 | mww | NaN | 12 | 6.393 | 0.93 | us | usb000rzki | 2014-10-29T19:52:55.000Z | Federated States of Micronesia region | earthquake |
2014-06-23 19:19:15.940 | -29.9772 | -177.7247 | 20.00 | 6.9 | mww | NaN | 35 | 0.751 | 0.99 | us | usc000rkg5 | 2014-09-19T17:23:16.000Z | 80km SSE of Raoul Island, New Zealand | earthquake |
2014-02-12 09:19:49.060 | 35.9053 | 82.5864 | 10.00 | 6.9 | mww | NaN | 18 | 7.496 | 0.83 | us | usc000mnvj | 2015-01-30T23:03:45.902Z | 272km ESE of Hotan, China | earthquake |
2014-07-21 14:54:41.000 | -19.8015 | -178.4001 | 615.42 | 6.9 | mww | NaN | 15 | 3.934 | 0.96 | us | usb000ruzk | 2014-10-17T21:12:13.000Z | 99km NNE of Ndoi Island, Fiji | earthquake |
2014-04-01 23:57:58.790 | -19.8927 | -70.9455 | 28.42 | 6.9 | mww | NaN | 119 | 0.828 | 0.93 | us | usc000nzwm | 2014-05-29T23:32:13.000Z | 91km WNW of Iquique, Chile | earthquake |
2014-05-24 09:25:02.440 | 40.2893 | 25.3889 | 6.43 | 6.9 | mww | NaN | 25 | 0.402 | 0.67 | us | usb000r2hc | 2015-01-28T09:17:17.266Z | 22km SSW of Kamariotissa, Greece | earthquake |
2014-07-07 11:23:54.780 | 14.7240 | -92.4614 | 53.00 | 6.9 | mww | NaN | 51 | 0.263 | 1.38 | us | usc000rr6a | 2015-01-28T13:08:13.282Z | 4km W of Puerto Madero, Mexico | earthquake |
gb = d.groupby('mag')
#gb['depth'].count().plot() # not necessary
#d['mag'].hist(by=d['mag']) # didn't work
d.hist('mag', bins=20)
ax = plt.gca()
ax.set_yscale('log')
d.groupby(pd.TimeGrouper('1d'), axis=0)['mag'].count().plot()
<matplotlib.axes._subplots.AxesSubplot at 0x10fe234e0>
d.groupby(pd.TimeGrouper('1h'), axis=0)['mag'].count().plot()
<matplotlib.axes._subplots.AxesSubplot at 0x10e068a90>
fig = plt.figure(figsize=(12,7))
ax = fig.add_subplot(111)
subplot = df.plot(kind='scatter', x='longitude', y='latitude', c='mag', ax=ax, cmap='RdBu_r')
#subplot.set_xlim([0,20])
#hbin.set_c
from matplotlib.colors import Colormap
from matplotlib.cm import ScalarMappable
# bokeh version
from bokeh.plotting import figure, show, output_notebook
output_notebook()
p = figure(title = "Earthquakes", width=900, height=500,)
p.xaxis.axis_label = 'lon'
p.yaxis.axis_label = 'lat'
sm = ScalarMappable(cmap='Greens')
rgb = (255*sm.to_rgba(df['mag'].values)[:,:3]).astype('int')
colors = ["#%02x%02x%02x" % tuple(c) for c in rgb]
p.scatter(df['longitude'], df['latitude'],
fill_color=colors, fill_alpha=0.6, line_color=None)
show(p)