请选择 进入手机版 | 继续访问电脑版
爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 27719|回复: 11

[源代码] python后向轨迹绘图方法

[复制链接]

新浪微博达人勋

发表于 2021-5-17 12:16:09 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
先上图
0.png
代码如下:
import os
import pandas as pd
import cartopy.crs as ccrs
import cartopy.mpl.ticker as cticker
import matplotlib.pyplot as plt
import matplotlib.colors as col
import matplotlib.cm as cm
import cartopy.feature as cfeature
import cartopy.io.shapereader as shpreader
import numpy as np
from matplotlib.collections import LineCollection
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号



#地图设置
proj = ccrs.PlateCarree(central_longitude=105)
leftlon, rightlon, lowerlat, upperlat = (70,135,18,55)
img_extent = [leftlon, rightlon, lowerlat, upperlat]
lon_formatter = cticker.LongitudeFormatter()
lat_formatter = cticker.LatitudeFormatter()
fig = plt.figure(figsize=(10,10))
f_ax = fig.add_axes([0.1, 0.3, 0.8, 0.6],projection = proj)
f_ax.set_extent(img_extent, crs=ccrs.PlateCarree())
f_ax.add_feature(cfeature.COASTLINE.with_scale('50m'))
f_ax.add_feature(cfeature.LAKES, alpha=0.5)
f_ax.set_xticks(np.arange(leftlon,rightlon+10,10), crs=ccrs.PlateCarree())
f_ax.set_yticks(np.arange(lowerlat,upperlat+10,10), crs=ccrs.PlateCarree())
f_ax.xaxis.set_major_formatter(lon_formatter)
f_ax.yaxis.set_major_formatter(lat_formatter)
# 加载中国地图
china = shpreader.Reader('data/bou2_4l.dbf').geometries()
#绘制中国国界省界九段线等等
f_ax.add_geometries(china, ccrs.PlateCarree(),facecolor='none', edgecolor='black',zorder = 1)
# color1 = '#00E400'
# color3 = '#FF7E00'
# color6 = '#7E0023'

color1 = 'green'
color3 = 'blue'
color6 = 'red'

cmap1 = col.LinearSegmentedColormap.from_list('own1', [color1,color1])
cm.register_cmap(cmap=cmap1)
cmap2 = col.LinearSegmentedColormap.from_list('own2', [color3,color3])
cm.register_cmap(cmap=cmap2)
cmap3 = col.LinearSegmentedColormap.from_list('own3', [color6,color6])
cm.register_cmap(cmap=cmap3)
h = h100['height']
points = np.array([h100['lon'], h100['lat']]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
#设置颜色线条
lc = LineCollection(segments, cmap=cm.get_cmap('own1'), color = color1,transform=ccrs.PlateCarree(),label = '100m')
lc.set_array(h)
f_ax.add_collection(lc)
h = h500['height']
points = np.array([h500['lon'], h500['lat']]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
#设置颜色线条
lc = LineCollection(segments, cmap=cm.get_cmap('own2'), color = color3,transform=ccrs.PlateCarree(),label = '500m')
lc.set_array(h)
f_ax.add_collection(lc)
h = h1000['height']
points = np.array([h1000['lon'], h1000['lat']]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
#设置颜色线条
lc = LineCollection(segments, cmap=cm.get_cmap('own3'), color = color6,transform=ccrs.PlateCarree(),label = '1000m')
lc.set_array(h)

#绘制线条
f_ax.add_collection(lc)
f_ax.scatter(h100['lon'][0], h100['lat'][0],color = 'black', s=10)
plt.title(str(h100['year'][0])+'年'+str(h100['month'][0])+'月'+str(h100['day'][0])+'日'+str(h100['hour'][0])+'时的'+str(int(h1000['bac_hour'][len(f)-1]))+'小时后向轨迹图')
plt.legend()
# f_ax = fig.add_axes([0.1, 0.5, 0.8, 0.4],projection = proj)
ff_ax = fig.add_axes([0.1, 0.1, 0.8, 0.22])
axx = range(-len(h100)+1,1)
ff_ax.plot(axx,h100['height'],color=color1)
ff_ax.plot(axx,h500['height'],color=color3)
ff_ax.plot(axx,h1000['height'],color=color6)
td = []
for i in range(len(h100['hour'])):
    l = str(h100['day'].tolist()
).replace(' ','') + '日' +str(h100['hour'].tolist()).replace(' ','')+ '时'
    td.append(l)
plt.xticks(axx, td, rotation=60)
plt.xlabel('时间')
plt.ylabel('高度:m')
plt.savefig('aaa.png')
plt.show()


密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2021-5-17 14:45:45 | 显示全部楼层
谢谢分享,学习了
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2021-5-17 15:01:21 | 显示全部楼层
谢谢分享,学习学习
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2021-5-31 16:52:12 | 显示全部楼层
绘制后向轨迹图读取的数据部分代码好像没有,读取的数据应为为风场数据,还有其他什么数据???
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2021-6-3 08:57:00 | 显示全部楼层
谢谢分享,我要好好学习
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2021-6-10 19:41:02 来自手机 | 显示全部楼层
正好在研究后向轨迹模拟,参考一下,感谢啦
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2021-7-4 07:20:37 | 显示全部楼层
谢谢分享,学习学习
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2023-3-17 19:59:06 | 显示全部楼层

                               
登录/注册后可看大图
大佬 您好,想问您两个问题,第一个问题就是在哪读取数据,第二个问题就是这个地方为啥报错
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2023-3-17 20:03:37 | 显示全部楼层

                               
登录/注册后可看大图
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2023-3-17 20:05:56 | 显示全部楼层
  1. h = h100['height']
复制代码

这个h100标红
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表