Python地图散点可视化(DMS采样位点)

import pandas as pd
df=pd.read_csv('1972_data.csv')

df['DateTime']=pd.to_datetime(df['DateTime'])
df['Month'] = df['DateTime'].dt.month 

import matplotlib.pyplot as plt###引入库包
import numpy as np
import matplotlib as mpl
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import matplotlib.ticker as mticker



mpl.rcParams["font.family"] = 'Times New Roman' #默认字体类型
mpl.rcParams["mathtext.fontset"] = 'cm' #数学文字字体
mpl.rcParams["font.size"] = 8 #字体大小
mpl.rcParams["font.weight"] = 'bold' #字体粗细
mpl.rcParams["axes.linewidth"] = 0.75  #轴线边框粗细(默认的太粗了)


proj = ccrs.PlateCarree(central_longitude=0)  #中国为左
fig = plt.figure(figsize=(10,8),dpi=550)  # 创建画布
# 这一步可以设置主图在画布上的位置
ax = fig.subplots(1, 1, subplot_kw={'projection': proj},gridspec_kw={"left":0.12, "right":0.84, "top":0.95, "bottom":0.131})  # 创建子图

#-----------绘制地图-------------------------------------------

# ax.add_feature(cfeature.LAND.with_scale('50m'))####添加陆地######
ax.add_feature(cfeature.COASTLINE.with_scale('110m'),lw=0.35)#####添加海岸线#########
# ax.add_feature(cfeature.OCEAN.with_scale('50m'))######添加海洋########

#-----------添加经纬度---------------------------------------
extent=[-180,180,-90,90]##经纬度范围
dlon, dlat = 45, 30   #设置步长
xticks = np.arange(0, 360.1, dlon)  #设置绘图范围
yticks = np.arange(-90, 90.1, dlat)

# 设置经纬度线的性质
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, linewidth=0.275, color='k', alpha=0.9, linestyle='-.')
gl.top_labels=False #关闭上部经纬标签                                  
gl.right_labels=False
gl.xformatter = LONGITUDE_FORMATTER  #使横坐标转化为经纬度格式            
gl.yformatter = LATITUDE_FORMATTER                                        
gl.xlocator=mticker.FixedLocator(np.arange(-180,180,45))      
gl.ylocator=mticker.FixedLocator(np.arange(-90,90,30)) 
ax.spines['geo'].set_linewidth(0.8)#调节边框粗细

#设置坐标轴刻度的性质
ax.set_xticks(xticks, crs=ccrs.PlateCarree())  #图幅设置坐标轴刻度
ax.set_yticks(yticks, crs=ccrs.PlateCarree())
ax.tick_params(axis='x',width=0.7,colors='black',length=0)
ax.tick_params(axis='y',width=0.7,colors='black',length=0,labelrotation=90)

ax.set_title('DMS data sites in 1972',size=12,fontweight='bold')

# 设置经纬度标签的性质
for tick in ax.yaxis.get_major_ticks():
    tick.label1.set_verticalalignment('bottom')
ax.yaxis.get_major_ticks()[-1].set_visible(False)

for tick in ax.xaxis.get_major_ticks():
    tick.label1.set_horizontalalignment('right')

ax.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label=True))  #设置坐标轴刻度标签格式
ax.yaxis.set_major_formatter(LatitudeFormatter())

ax.set_extent(extent)     #显示所选择的区域

# 修改全局属性,修改字体为正常粗细
mpl.rcParams["font.weight"] = 'normal' #字体粗细

c=ax.scatter(df['Lon'],df['Lat'],c=df['Month'],transform=ccrs.PlateCarree(),s=50,alpha=0.6,cmap="Paired",vmin=0.5,vmax=12.5)

# 设置颜色棒的位置
cb_left=ax.get_position().x1+0.02
cb_bottom=ax.get_position().y0
cb_height=ax.get_position().y1-ax.get_position().y0
cb_width=0.04
position=fig.add_axes([cb_left, cb_bottom, cb_width, cb_height])#位置[左,下,宽度,高度]
fc=fig.colorbar(c,ax=ax,cax=position,ticks=[0,2,4,6,8,10,12])
fc.set_ticklabels(["0","2","4","6","8","10","12"])
# 设置颜色棒的刻度性质
ax2=fc.ax#调出colorbar的ax属性
ax2.set_title('Month',fontsize=10,fontweight='bold')
ax2.tick_params(axis='y',labelsize=8,length=2.3,width=0.7)

plt.savefig('ok.jpg',dpi=600)

如图所示:
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值