Код: Выделить всё
import os
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
#Disk, directories
work_disk = 'E:'
work_dir = work_disk + os.sep + '2015_For' + os.sep + '2015_for_N' + os.sep
#Change Directory
os.chdir(work_dir)
#File with points
file_ivp = "all_points_with_dates.txt"
full_path_file_ivp = work_dir + file_ivp
#Open File with points
f = open(full_path_file_ivp, 'r')
#Loop by Lines of File with points
for year_loop in range(1900,2000):
yes_or_no_points_for_this_year=False
#a pointer to the beginning of the file
f.seek(0)
#loop by words at line
nr_line=0
for line in f:
#list
list_line = line.split()
#station id
nbd_list = list_line[0]
#latitude
lat_list = list_line[1]
#longitude
lon_list = list_line[2]
#year
year_list = list_line[3]
#month
month_list = list_line[4]
if int(year_list)==year_loop:
if yes_or_no_points_for_this_year==False:
yes_or_no_points_for_this_year=True
#************************************************************************************
#Basemap, coast, continets, rivers
mp = Basemap(projection='nplaea', boundinglat=68, lon_0=130, resolution='l', area_thresh=1000)
mp.drawcoastlines(linewidth=0.2)
mp.fillcontinents(color='ivory',lake_color='aqua')
mp.drawrivers(color='aqua')
#Meridians
meridians = np.arange(0.,351.,10.)
mp.drawmeridians(meridians,labels=[1,1,1,1],linewidth=0.125,latmax=89,fontsize=8)
meridians_thin = np.arange(0.,351.,5.)
mp.drawmeridians(meridians_thin,labels=[0,0,0,0],linewidth=0.07,latmax=89)
meridians_bold = np.arange(0.,351.,90.)
mp.drawmeridians(meridians_bold,labels=[0,0,0,0],linewidth=0.25,latmax=89,dashes=[0.01,0.01])
#Parallels
parallels = np.arange(0.,90.,1.)
mp.drawparallels(parallels,linewidth=0.125)
parallels_thin = np.arange(0.,90.,0.5)
mp.drawparallels(parallels_thin,linewidth=0.07)
parallels_bold = np.arange(0.,90.,5.)
mp.drawparallels(parallels_bold,linewidth=0.25,dashes=[0.01,0.01])
#ETOPO
mp.etopo(alpha=0.37)
ax = plt.gca()
#Parallels Labels by annotation
for lat_an in range(69,89):
x_crd=310.
y_crd=float(lat_an)
txt_an=str(lat_an)+'$^\circ$'+'N'
ax.annotate(txt_an, xy=mp(x_crd, y_crd), xycoords='data', clip_on=False, size=8, ha='center', va='center')
#************************************************************************************
first_line=nr_line
print "Year:", year_loop
nr_for_this_year=0
#Year annotation
txt_year_an=str(year_loop)
#PNG file Name
png_file=work_dir+"Png_"+txt_year_an+".png"
print png_file
x, y = mp(90,63)
plt.text(x, y, txt_year_an, fontsize=12, fontweight='bold',
ha='left',va='center',color='k',
bbox=dict(facecolor='b', alpha=0.2))
#calculate plot coordinates for point
x,y = mp(float(lon_list), float(lat_list))
mp.plot(x, y, marker=".", color="blue", markersize=2, alpha=0.5)
nr_for_this_year=nr_for_this_year+1
nr_line=nr_line+1
plt.savefig(png_file)
plt.clf()
f.close()