# 麋鹿分布图制作（二）—— 用Python和R在地图上打点

1. library(rgdal)

2. library(ggplot2)

3. library(mapproj)

4. library(xlsx)

5. # 设置一下工作路径

6. setwd('D:/class/zonglv')

7. # 读取文件

8. milu = read.xlsx('milu.xlsx', 1, encoding = 'UTF-8')

9. # 读取中国地图

11. # 转化为数据框

12. china_map <- fortify(china_map)

13. p = ggplot() +

14.     geom_polygon(data=china_map, aes(x=long, y=lat, group = group), colour="grey60", size = 0.25) +

15.     geom_point(data = milu, aes(x = lon,y = lat, color = time, shape = species), size = 1.5) +

16.    coord_map("polyconic")

17. p

1. import time

2. from mpl_toolkits.basemap import Basemap

3. import matplotlib.pyplot as plt

4. from matplotlib.patches import Polygon

5. import pandas as pd

6. import numpy as np

2. # 我们还是先把数据读入进来

3. plt.figure(figsize = (16,8))

4. m = Basemap(llcrnrlon=77,llcrnrlat=14,urcrnrlon=140,urcrnrlat=51,projection='lcc',lat_1=33,lat_2=45,lon_0=100)

5. m.drawcoastlines()

6. m.drawcountries(linewidth=1.5)

8. lats = list(ml['lat'])

9. lons = list(ml['lon'])

10. x, y = m(lons, lats)

11. m.scattter(x,y,3,marker = 'o', color = 'red')

12. plt.show()

http://blog.sciencenet.cn/blog-3412381-1184194.html

## 全部精选博文导读

GMT+8, 2020-2-29 05:58