- Notifications
You must be signed in to change notification settings - Fork 397
/
Copy pathhires.py
51 lines (42 loc) · 1.48 KB
/
hires.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from __future__ importprint_function
importtime
importpickle
importnumpyasnp
importmatplotlib.pyplotasplt
frommpl_toolkits.basemapimportBasemap
# Create figure.
fig=plt.figure()
# Create Basemap instance:
# - Use 'full' resolution coastlines.
# - Make sure that countries and rivers are loaded.
t0=time.time()
bmap1=Basemap(width=920000, height=1100000, resolution="f",
projection="tmerc", lon_0=-4.2, lat_0=54.6)
bmap1.drawcountries()
bmap1.drawrivers()
t1=time.time()
print("{0:.3f} secs to plot with a Basemap instance created at runtime".format(t1-t0))
# Clear the figure.
plt.clf()
# Pickle the class instance.
withopen("map.pickle", "wb") asfd:
pickle.dump(bmap1, fd, protocol=-1)
# Read pickle back in and plot it again (should be much faster):
# - Draw coastlines and fill continents and lakes.
# - Draw political boundaries and rivers.
# - Draw parallels and meridians.
# - Draw map boundary and fill map background.
t0=time.time()
withopen("map.pickle", "rb") asfd:
bmap2=pickle.load(fd)
bmap2.drawcoastlines()
bmap2.fillcontinents(color="coral", lake_color="aqua")
bmap2.drawcountries(linewidth=1)
bmap2.drawrivers(color="b")
bmap2.drawparallels(np.arange(48, 65, 2), labels=[1, 1, 0, 0])
bmap2.drawmeridians(np.arange(-12, 13, 2), labels=[0, 0, 1, 1])
bmap2.drawmapboundary(fill_color="aqua")
t1=time.time()
print("{0:.3f} secs to plot with a pickled Basemap instance".format(t1-t0))
plt.title("High-Res British Isles", y=1.04)
plt.show()