cartopy绘制世界地图(太平洋位于中心)

1.安装cartopy

(1)python环境-3.7

总是报错,试了好多方法不行,同事用的3.9版本的就可以,于是直接换了3.9版本镜像。

(2)python环境-3.9

Python3.9版本镜像中包含Cartopy 0.20模块

2.实例图

这里将太平洋划分为两块,不够美观。

import geopandas as gpd
import matplotlib.pyplot as plt
import pandas as pd
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import os
fig, ax = plt.subplots(figsize=(16, 10), subplot_kw={'projection': ccrs.PlateCarree()})
ax.coastlines()
plt.savefig('./test.png')
#将地球三维球体投影到二维面上,减少失真。
#主要方式有默认投影(PlateCarree)、兰勃脱投影(Lambert)、墨卡托投影(Mercator)、极投影。

3.修改中心经线

为了以太平洋位于中心,需要修改中心经线

ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))#全球图像的中央位于太平洋的 180 度经线处

4.添加feature

import cartopy.feature as cfeature
ax.add_feature(cfeature.LAND) # 添加陆地
ax.add_feature(cfeature.COASTLINE,lw=0.3)# 添加海岸线
ax.add_feature(cfeature.RIVERS,lw=0.25)# 添加河流
ax.add_feature(cfeature.LAKES)# 添加湖泊
ax.add_feature(cfeature.BORDERS, linestyle='-',lw=0.25)# 不推荐,我国丢失了藏南、台湾等领土
ax.add_feature(cfeature.OCEAN)#添加海洋

5.将经纬度标记在世界地图上

import geopandas as gpd
import matplotlib.pyplot as plt
import pandas as pd
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import os
df = pd.read_csv('F:/11-7/原始数据分组/2018_2022_按月分类/2018-01.csv')    
data = df[(df['lat'] >= -90) & (df['lat'] <= 90) & (df['lon'] >= -180) & (df['lon'] <= 180)]
lat = data['lat']
lon = data['lon']
lon = [180+lon_val for lon_val in lon] 
fig, ax = plt.subplots(figsize=(16, 10), subplot_kw={'projection': ccrs.PlateCarree(central_longitude=180)})
ax.coastlines()
ax.add_feature(cfeature.LAND) # 添加陆地
ax.add_feature(cfeature.COASTLINE,lw=0.3)# 添加海岸线
ax.add_feature(cfeature.RIVERS,lw=0.25)# 添加河流
ax.add_feature(cfeature.LAKES)# 添加湖泊
ax.add_feature(cfeature.OCEAN)#添加海洋
ax.scatter(lon, lat, color='red', s=1)
ax.set_title('test', fontsize=20)
ax.set_xticks(range(-180, 181, 60))
ax.set_xticklabels(['0°', '60°E', '120°E', '180°', '120°W', '60°W', '0°'], fontsize=10)
ax.set_yticks(range(-90, 91, 30))
ax.set_yticklabels(['90°S', '60°S', '30°S', '0°', '30°N', '60°N', '90°N'], fontsize=10)
plt.savefig('./轨迹图.png')

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值