Skip to content

Commit 683f0a6

Browse files
committed
submit code
1 parent 6a877d4 commit 683f0a6

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

chaoxi/BaseMap/Python_BaseMap1.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import matplotlib.pyplot as plt
2+
from mpl_toolkits.basemap import Basemap
3+
import numpy as np
4+
5+
# 画海岸线
6+
def drawcoast():
7+
8+
plt.figure(figsize=(12, 8))
9+
m = Basemap() # 创建一个地图
10+
m.drawcoastlines() # 画海岸线
11+
plt.show() # 显示图像
12+
13+
# 地球基本画法
14+
def draw_basic():
15+
map = Basemap(projection='ortho', lat_0=0, lon_0=0)
16+
map.drawmapboundary(fill_color='aqua')
17+
map.fillcontinents(color='gray',lake_color='aqua')
18+
map.drawcoastlines()
19+
plt.show()
20+
21+
# 画中国地图
22+
def draw_china():
23+
plt.figure(figsize=(10, 6))
24+
m = Basemap(llcrnrlon=77, llcrnrlat=14, urcrnrlon=140, urcrnrlat=51, projection='lcc', lat_1=33, lat_2=45,
25+
lon_0=100)
26+
m.drawcountries(linewidth=1.5)
27+
m.drawcoastlines()
28+
plt.show()
29+
30+
# 画地球人口分布图
31+
def drawearth():
32+
names = []
33+
pops = []
34+
lats = []
35+
lons = []
36+
countries = []
37+
file = open("data/main_city", encoding='utf-8').readlines()
38+
for line in file:
39+
info = line.split()
40+
names.append(info[0])
41+
pops.append(float(info[1]))
42+
lat = float(info[2][:-1])
43+
if info[2][-1] == 'S': lat = -lat
44+
lats.append(lat)
45+
lon = float(info[3][:-1])
46+
if info[3][-1] == 'W': lon = -lon + 360.0
47+
lons.append(lon)
48+
country = info[4]
49+
countries.append(country)
50+
# set up map projection with
51+
# use low resolution coastlines.
52+
map = Basemap(projection='ortho', lat_0=35, lon_0=120, resolution='l')
53+
# draw coastlines, country boundaries, fill continents.
54+
map.drawcoastlines(linewidth=0.25)
55+
map.drawcountries(linewidth=0.25)
56+
# draw the edge of the map projection region (the projection limb)
57+
map.drawmapboundary(fill_color='#689CD2')
58+
# draw lat/lon grid lines every 30 degrees.
59+
map.drawmeridians(np.arange(0, 360, 30))
60+
map.drawparallels(np.arange(-90, 90, 30))
61+
# Fill continent wit a different color
62+
map.fillcontinents(color='#BF9E30', lake_color='#689CD2', zorder=0)
63+
# compute native map projection coordinates of lat/lon grid.
64+
x, y = map(lons, lats)
65+
max_pop = max(pops)
66+
# Plot each city in a loop.
67+
# Set some parameters
68+
size_factor = 80.0
69+
y_offset = 15.0
70+
rotation = 30
71+
for i, j, k, name in zip(x, y, pops, names):
72+
size = size_factor * k / max_pop
73+
cs = map.scatter(i, j, s=size, marker='o', color='#FF5600')
74+
plt.text(i, j + y_offset, name, rotation=rotation, fontsize=10)
75+
76+
plt.title('earth')
77+
plt.show()
78+
79+
# 画带投影的地球图片
80+
def draw_earth1():
81+
import matplotlib.pyplot as plt
82+
from mpl_toolkits.basemap import Basemap
83+
plt.figure(figsize=(8, 8))
84+
# 正射投影,投影原点设在了上海周边
85+
m = Basemap(projection='ortho', resolution=None, lat_0=30, lon_0=120)
86+
# 图像原始分辨率是5400*2700,设置scale = 0.5以后分辨率为2700*1350,如此作图
87+
# 迅速不少也不那么占用内存了
88+
m.bluemarble(scale=0.5)
89+
plt.show()
90+
91+
if __name__ == '__main__':
92+
#drawcoast()
93+
drawearth()
94+
#draw_basic()
95+
#draw_china()
96+
#draw_earth1()

chaoxi/BaseMap/main_city

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Shanghai 23019148 31.23N 121.47E China
2+
Mumbai 12478447 18.96N 72.82E India
3+
Karachi 13050000 24.86N 67.01E Pakistan
4+
Delhi 16314838 28.67N 77.21E India
5+
Manila 11855975 14.62N 120.97E Philippines
6+
Seoul 23616000 37.56N 126.99E Korea(South)
7+
Jakarta 28019545 6.18S 106.83E Indonesia
8+
Tokyo 35682460 35.67N 139.77E Japan
9+
Peking 19612368 39.91N 116.39E China

chaoxi/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Python技术 公众号文章代码库
99

1010
## 实例代码
1111

12+
[神器-可视化分析之Basemap实战详解(二)](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/BaseMap) 神器-可视化分析之Basemap实战详解(二)
13+
1214
[用 Python 给小表弟画皮卡丘!](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/pkq) 用 Python 给小表弟画皮卡丘!
1315

1416
[惊艳!利用 Python 图像处理绘制专属头像](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/opencv_img) 惊艳!利用 Python 图像处理绘制专属头像

0 commit comments

Comments
 (0)