-
Notifications
You must be signed in to change notification settings - Fork 18
/
Basemap_test.py
155 lines (123 loc) · 5.29 KB
/
Basemap_test.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import matplotlib
matplotlib.use('Agg')
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import matplotlib.cm
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
from matplotlib.colors import Normalize
def FullGlobePerspective():
fig, ax = plt.subplots(figsize=(12, 10))
# setup Lambert Conformal basemap.
m = Basemap(width=1800000,height=1500000,projection='nsper',area_thresh = 100000,
resolution='h',lat_1=45.,lat_2=55,lat_0=25.7,lon_0=91.5, satellite_height = 10000000)
# draw coastlines.
m.drawcoastlines()
# draw a boundary around the map, fill the background.
# this background will end up being the ocean color, since
# the continents will be drawn on top.
m.drawmapboundary(fill_color='aqua')
# fill continents, set lake color same as ocean color.
m.fillcontinents(color='peru',lake_color='aqua')
# draw parallels and meridians.
# label parallels on right and top
# meridians on bottom and left
parallels = np.arange(0.,81,5.)
# labels = [left,right,top,bottom]
m.drawparallels(parallels,labels=[False,True,True,False])
meridians = np.arange(10.,351.,5.)
m.drawmeridians(meridians,labels=[True,False,False,True])
m.drawcountries()
m.readshapefile('Mega_divide_footprint', 'MDF')
# All this stuff from:
# http://www.datadependence.com/2016/06/creating-map-visualisations-in-python/
df_poly = pd.DataFrame({
'shapes': [Polygon(np.array(shape), True) for shape in m.MDF]})
print(df_poly)
#df_poly = df_poly.merge(new_areas, on='area', how='left')
cmap = plt.get_cmap('Oranges')
pc = PatchCollection(df_poly.shapes, zorder=2)
pc.set_facecolor(cmap(1))
ax.add_collection(pc)
FigFileName = "Test.png"
FigFormat = "png"
plt.savefig(FigFileName,format=FigFormat,dpi=200)
def ZoomPerspective():
fig, ax = plt.subplots(figsize=(6, 5))
# setup Lambert Conformal basemap.
print("I am trying to get rid of these bloody lakes")
m = Basemap(width=1800000,height=1500000,projection='lcc',area_thresh=10000000.,
resolution='l',lat_1=45.,lat_2=55,lat_0=25.7,lon_0=91.5)
# draw coastlines.
m.drawcoastlines()
# draw a boundary around the map, fill the background.
# this background will end up being the ocean color, since
# the continents will be drawn on top.
m.drawmapboundary(fill_color='aqua')
# fill continents, set lake color same as ocean color.
m.fillcontinents(color='peru',lake_color='aqua')
# draw parallels and meridians.
# label parallels on right and top
# meridians on bottom and left
parallels = np.arange(0.,81,5.)
# labels = [left,right,top,bottom]
m.drawparallels(parallels,labels=[False,True,True,False])
meridians = np.arange(10.,351.,5.)
m.drawmeridians(meridians,labels=[True,False,False,True])
m.drawcountries()
m.readshapefile('Mega_divide_footprint', 'MDF')
# All this stuff from:
# http://www.datadependence.com/2016/06/creating-map-visualisations-in-python/
df_poly = pd.DataFrame({
'shapes': [Polygon(np.array(shape), True) for shape in m.MDF]})
print(df_poly)
#df_poly = df_poly.merge(new_areas, on='area', how='left')
cmap = plt.get_cmap('Oranges')
pc = PatchCollection(df_poly.shapes, zorder=2, alpha = 0.5)
pc.set_facecolor("r")
ax.add_collection(pc)
FigFileName = "Test.png"
FigFormat = "png"
plt.savefig(FigFileName,format=FigFormat,dpi=200)
def ZoomPerspectiveEtopo():
fig, ax = plt.subplots(figsize=(3, 2.5))
# setup Lambert Conformal basemap.
print("I am trying to get rid of these bloody lakes")
m = Basemap(width=1800000,height=1500000,projection='lcc',area_thresh=10000000.,
resolution='h',lat_1=45.,lat_2=55,lat_0=25.7,lon_0=91.5)
# draw coastlines.
#m.drawrivers()
m.drawcoastlines()
# draw a boundary around the map, fill the background.
# this background will end up being the ocean color, since
# the continents will be drawn on top.
m.drawmapboundary(fill_color='aqua')
# fill continents, set lake color same as ocean color.
m.fillcontinents(color='peru',lake_color='white')
# draw parallels and meridians.
# label parallels on right and top
# meridians on bottom and left
parallels = np.arange(0.,81,5.)
# labels = [left,right,top,bottom]
m.drawparallels(parallels,labels=[False,True,True,False])
meridians = np.arange(10.,351.,5.)
m.drawmeridians(meridians,labels=[True,False,False,True])
m.drawcountries()
m.readshapefile('Mega_divide_footprint', 'MDF')
# All this stuff from:
# http://www.datadependence.com/2016/06/creating-map-visualisations-in-python/
df_poly = pd.DataFrame({
'shapes': [Polygon(np.array(shape), True) for shape in m.MDF]})
print(df_poly)
#df_poly = df_poly.merge(new_areas, on='area', how='left')
cmap = plt.get_cmap('Oranges')
pc = PatchCollection(df_poly.shapes, zorder=2, alpha = 0.5)
pc.set_facecolor("gray")
ax.add_collection(pc)
FigFileName = "Test.svg"
FigFormat = "svg"
plt.savefig(FigFileName,format=FigFormat,dpi=200)
if __name__ == "__main__":
ZoomPerspectiveEtopo()