我创建了一个地震动画,随着时间的推移绘制地震震中位置。我希望在左下角或右下角添加一个数字计数器,随着每个震中图而变化。因此,每次地震中的地图,数字都会增加。我如何编辑我的脚本(附在下面),这将允许这个注释到情节?感谢。
#!/usr/local/bin/python
############################################################################################
# #
# This script uses Matplotlib, the Basemap function, Matplotlib's animation function, #
# and numpy to iteratively plot a list of earthquake epicenters with the map centered #
# around Antarctica. #
# Created By: #
# Date: 09/12/2015 #
############################################################################################
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import numpy as np
import csv
# Create the Figure Object
fig = plt.figure()
# Build the basemap: In this case, using mercator projection
antmap = Basemap(projection='merc', llcrnrlat=26.729567, llcrnrlon=-127.041952, urcrnrlon=-63.409141, urcrnrlat=48.036699, resolution='l')
# Draw the coastlines and color them black.
antmap.drawcoastlines(color='black', linewidth=0.3)
# Option 1: Fill the continents with gray color, oceans as blue color
antmap.fillcontinents(color='gray', lake_color='aqua')
antmap.drawmapboundary(fill_color='aqua')
# Option 2: Fill map background with blue marble earth image
#antmap.bluemarble()
# Option 3: Fill map background Etopo topography (Figure will take longer to load)
#antmap.etopo()
# Open the earthquake data file using built-in open() function
eq_data = open('usquakes.csv')
# Create empty lists for latitudes, longitudes, and magnitudes
lats, lons = [], []
magnitudes = []
depth = []
# Assign variables x and y to longitude/latitude to be able to plot on map.
x,y = antmap(lons,lats)
def get_marker_color(magnitudes):
if magnitudes < 3.0:
return ('go')
elif magnitudes < 7.0:
return('yo')
else:
return ('ro')
# Read each line in comma-separated, 3-column file (Could also use CSV-module).
i=0
for i, line in enumerate(eq_data.readlines()):
lats.append(float(line.split(',')[0])) # 0 is first column, split on comma.
lons.append(float(line.split(',')[1]))
depth.append(line.split(',')[2])
magnitudes.append(float(line.split(',')[3]))
mag = np.array(magnitudes)*2
i = i + 1
#mag = np.array(magnitudes)*2 # Scale the magnitudes
# For scaling the magnitudes in a list, this has to be performed using np.array.
# Close earthquake data file
eq_data.close()
#antmap.plot(x,y,'ko',markersize=8)[0]
#### Begin Animation Function ######
def animate(i):
x,y = antmap(lons[i], lats[i])
marker_string = get_marker_color(magnitudes)
antmap.plot(x,y,marker_string, markersize=mag[i])
# Call FuncAnimation, using an interval of 100 ms, and on Mac OSX, set blit=False
animation = FuncAnimation(fig, animate, interval=10, blit=False)
# Show the figure!
plt.show()
# Optionally save animation as .mp4 file (must have ffmpeg installed).
#animation.save('earthquake_animation.mp4', writer="ffmpeg")