python怎么编程输入坐标_[原创]python绘制地图的利器Cartopy使用说明

import matplotlib.path as mpath

import matplotlib.pyplot as plt

import numpy as np

import matplotlib.ticker as mticker

import cartopy.crs as ccrs

import cartopy.feature as cfeature

fig=plt.figure(figsize=(6, 6))

ax=plt.axes(projection=ccrs.NorthPolarStereo())

box=[-180, 180, 55, 90]

xstep,ystep=30,15

# Limit the map to -60 degrees latitude and below.

ax.set_extent(box, crs=ccrs.PlateCarree())

scale='50m'

land = cfeature.NaturalEarthFeature('physical', 'land', scale,edgecolor='face',

facecolor=cfeature.COLORS['land'])

ocean = cfeature.NaturalEarthFeature('physical', 'ocean', scale,edgecolor='face',

facecolor=cfeature.COLORS['water'])

ax.add_feature(land,facecolor='0.75')

ax.add_feature(ocean,facecolor='blue')

ax.coastlines(scale,linewidth=0.9)

#标注坐标轴

line=ax.gridlines(draw_labels=False)

line.ylocator=mticker.FixedLocator(np.arange(40,90,20))#手动设置x轴刻度

line.xlocator=mticker.FixedLocator(np.arange(-180,210,30))#手动设置x轴刻度

# Compute a circle in axes coordinates, which we can use as a boundary

# for the map. We can pan/zoom as much as we like - the boundary will be

# permanently circular.

theta = np.linspace(0, 2*np.pi, 100)

center, radius = [0.5, 0.5], 0.5

verts = np.vstack([np.sin(theta), np.cos(theta)]).T

circle = mpath.Path(verts * radius + center)

ax.set_boundary(circle, transform=ax.transAxes)

#创建要标注的labels字符串

ticks=np.arange(0,210,30)

etick=['0']+['%d$^\circ$E'%tick for tick in ticks if (tick !=0) & (tick!=180)]+['180']

wtick=['%d$^\circ$W'%tick for tick in ticks if (tick !=0) & (tick!=180)]

labels=etick+wtick

#创建与labels对应的经纬度标注位置

#xticks=[i for i in np.arange(0,210,30)]+[i for i in np.arange(-32,-180,-30)]

xticks=[-0.8,28,58,89.1,120,151,182.9,-36,-63,-89,-114,-140]

yticks=[53]+[53]+[54]+[55]*2+[54.5]+[54]+[50]+[49]*3+[50.6]

#标注经纬度

#ax.text(0.01,0.23,'60$^\circ$W',transform=ax.transAxes,rotation=25)

#ax.text(-63,50,'60$^\circ$W',transform=ccrs.Geodetic(),rotation=25)

for xtick,ytick,label in zip(xticks,yticks,labels):

ax.text(xtick,ytick,label,transform=ccrs.Geodetic())

x=[180, 180, 0, 0]

y=[50, 90, 90, 50]

ax.plot([-180,0],[80,80],':',transform=ccrs.Geodetic(),color='k',linewidth=0.4)

ax.plot([-90,90],[80,80],':',transform=ccrs.Geodetic(),color='k',linewidth=0.5)

#ax.plot([90,0],[50,50],'-.',transform=ccrs.Geodetic(),color='r',linewidth=6)

ax.text(11.9333,78.9166,r'$\bigstar,transform=ccrs.Geodetic(),size=15,color='r')

fig.savefig(u'c:\\北极.png',dpi=300)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值