# -----------------------------------------------------------------------------
# Copyright (c) 2014, Nicolas P. Rougier. All Rights Reserved.
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------
# Based on : https://peak5390.wordpress.com
# -> 2012/12/08/matplotlib-basemap-tutorial-plotting-global-earthquake-activity/
# -----------------------------------------------------------------------------
import urllib
import numpy as np
import matplotlib
matplotlib.rcParams['toolbar'] = 'None'
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from matplotlib.animation import FuncAnimation
# Open the earthquake data
# -------------------------
# -> http://earthquake.usgs.gov/earthquakes/feed/v1.0/csv.php
feed = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/"
# Significant earthquakes in the past 30 days
# url = urllib.urlopen(feed + "significant_month.csv")
# Earthquakes of magnitude > 4.5 in the past 30 days
url = urllib.request.urlopen(feed + "4.5_month.csv")
# Earthquakes of magnitude > 2.5 in the past 30 days
# url = urllib.urlopen(feed + "2.5_month.csv")
# Earthquakes of magnitude > 1.0 in the past 30 days
# url = urllib.urlopen(feed + "1.0_month.csv")
# Set earthquake data
data = url.read()
data = data.split(b'\n')[+1:-1]
E = np.zeros(len(data), dtype=[('position', float, 2),
('magnitude', float, 1)])
for i in range(len(data)):
row = data[i].split(b',')
E['position'][i] = float(row[2]),float(row[1])
E['magnitude'][i] = float(row[4])
fig = plt.figure(figsize=(14,10))
ax = plt.subplot(1,1,1)
P = np.zeros(50, dtype=[('position', float, 2),
('size', float, 1),
('growth', float, 1),
('color', float, 4)])
# Basemap projection
map = Basemap(projection='mill')
map.drawcoastlines(color='0.50', linewidth=0.25)
map.fillcontinents(color='0.95')
scat = ax.scatter(P['position'][:,0], P['position'][:,1], P['size'], lw=0.5,
edgecolors = P['color'], facecolors='None', zorder=10)
def update(frame):
current = frame % len(E)
i = frame % len(P)
P['color'][:,3] = np.maximum(0, P['color'][:,3] - 1.0/len(P))
P['size'] += P['growth']
magnitude = E['magnitude'][current]
P['position'][i] = map(*E['position'][current])
P['size'][i] = 5
P['growth'][i]= np.exp(magnitude) * 0.1
if magnitude < 6:
P['color'][i] = 0,0,1,1
else:
P['color'][i] = 1,0,0,1
scat.set_edgecolors(P['color'])
scat.set_facecolors(P['color']*(1,1,1,0.25))
scat.set_sizes(P['size'])
scat.set_offsets(P['position'])
plt.title("Earthquakes > 4.5 in the last 30 days")
animation = FuncAnimation(fig, update, interval=10)
plt.show()
没有合适的资源?快使用搜索试试~ 我知道了~
matplotlib - tutorial:matplotlib 的源代码资源
共285个文件
png:214个
py:67个
ds_store:2个
0 下载量 104 浏览量
2024-01-15
19:08:43
上传
评论
收藏 3.23MB ZIP 举报
温馨提示
matplotlib - tutorial:matplotlib 的源代码资源
资源推荐
资源详情
资源评论
收起资源包目录
matplotlib - tutorial:matplotlib 的源代码资源 (285个子文件)
.DS_Store 10KB
.DS_Store 10KB
rain.gif 1.56MB
.gitignore 25B
earthquakes.png 147KB
scatter.png 145KB
scatter_ex.png 103KB
plot3d.png 87KB
plot3d_ex.png 67KB
polar.png 57KB
text.png 54KB
pie.png 53KB
text_ex.png 47KB
polar_ex.png 44KB
contour.png 39KB
rain-static.png 37KB
quiver.png 34KB
pie_ex.png 33KB
legend.png 29KB
contourf.png 27KB
quiver_ex.png 25KB
ticks.png 25KB
arrow.png 25KB
loglog.png 25KB
exercice_10.png 25KB
exercice_9.png 24KB
subplots_four.png 24KB
contour_ex.png 23KB
subplots_horizontal.png 23KB
exercice_2.png 22KB
exercice_1.png 22KB
exercice_3.png 21KB
exercice_4.png 21KB
exercice_5.png 20KB
exercice_8.png 20KB
simple.png 20KB
exercice_6.png 19KB
plot.png 19KB
exercice_7.png 19KB
imshow.png 18KB
date.png 17KB
subplots_vertical.png 17KB
stem.png 15KB
hist.png 14KB
barh.png 14KB
axes-2.png 13KB
spy.png 12KB
broken_barh.png 12KB
plot_ex.png 12KB
bar.png 10KB
boxplot.png 10KB
multiplot.png 10KB
gridspec.png 10KB
grid.png 9KB
axes.png 8KB
subplot-horizontal.png 8KB
imshow_ex.png 8KB
bar_ex.png 8KB
subplot-grid.png 7KB
subplot-vertical.png 5KB
grid_ex.png 3KB
ticks-MultipleLocator.png 3KB
ticks-LinearLocator.png 2KB
ticks-MinuteLocator.png 2KB
ticks-AutoLocator.png 2KB
ticks-FixedLocator.png 2KB
dash_joinstyle.png 2KB
cmap-flag.png 2KB
antialiased.png 2KB
ticks-LogLocator.png 1KB
cmap-prism.png 1KB
multiplot_ex.png 1KB
ticks-IndexLocator.png 1KB
mec.png 957B
solid_joinstyle.png 954B
mew.png 849B
cmap-Set3.png 755B
marker-5.png 753B
marker-7.png 726B
cmap-Paired.png 725B
marker-6.png 707B
cmap-Dark2.png 694B
cmap-Accent.png 692B
cmap-Set1.png 676B
linestyle-d.png 652B
marker-d.png 651B
cmap-gist_ncar.png 625B
cmap-PuOr.png 615B
cmap-PiYG.png 597B
cmap-Set2.png 591B
cmap-coolwarm.png 580B
cmap-RdBu.png 580B
cmap-PuRd.png 579B
mfc.png 571B
cmap-Pastel2.png 567B
cmap-gnuplot.png 566B
cmap-gist_earth.png 565B
cmap-RdYlBu.png 563B
cmap-PRGn.png 562B
cmap-rainbow.png 560B
共 285 条
- 1
- 2
- 3
资源评论
诗者才子酒中仙
- 粉丝: 5244
- 资源: 1018
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功