gpt4 book ai didi

python - 如何根据强度用标记颜色绘制气旋的轨迹

转载 作者:行者123 更新时间:2023-12-04 09:42:05 27 4
gpt4 key购买 nike

我正在尝试在 basemap 上绘制气旋的轨迹。我成功地用相同颜色的标记绘制它,我想要的是根据强度变化绘制标记。我将附上我能够使用相同颜色标记绘制轨迹的代码部分。如果有人可以在这方面帮助我如何根据强度绘制轨迹,将不胜感激。
我的代码:

llons, llats = np.meshgrid(lons, lats)
x,y = map(llons,llats)
plt.style.use('seaborn-white')
clevels=[-1.6,-1.2,-0.8,-0.4,0.0,0.4,0.8]
cs = map.contourf(x,y,plt_data,clevels,cmap=plt.cm.jet)
#cs = map.contourf(x,y,plt_data,cmap=plt.cm.jet)
#CS2 = ax.contour(cs, levels=cs.levels, colors='k')
#ax.clabel(cs,inline=True, fontsize=10)
map.colorbar(cs)
####################track##########################
import pandas as pd
df = pd.read_excel('E:/bst_trc.xls',sheet_name='1990')
latitude = df.Latitude.values[0:25]
longitude = df.Longitude.values[0:25]
it = df.Grade.values[0:25]
x,y = map(longitude, latitude)
colors = {'SUCS':'red', 'ESCS':'blue', 'SCS':'green', 'D':'black','VSCS':'orange','DD':'cyan'}
plt.scatter(x,y, s=50,edgecolors="red", facecolors='none', linewidth=2)
plt.plot(x,y,'k',linewidth=1.5 )

另外,我附上了经纬度和强度值:

enter image description here

最佳答案

使用您的数据和此代码:

import matplotlib.pyplot as plt
import pandas as pd
plt.style.use('seaborn-white')

df = pd.read_csv('data.csv')

colors = {'SUCS': 'red', 'ESCS': 'blue', 'SCS': 'green', 'D': 'black', 'VSCS': 'orange', 'DD': 'cyan', 'CS': 'magenta'}

fig, ax = plt.subplots(1, 1)

for grade in list(df['grade'].unique()):
ax.scatter(df[df['grade'] == grade]['lon'],
df[df['grade'] == grade]['lat'],
s = 50,
label = grade,
facecolors = colors[grade])

plt.plot(df['lon'], df['lat'], 'k-', lw = 1)

ax.set_xlabel('Longitude')
ax.set_ylabel('Latitude')
ax.axis('equal')

plt.legend()
plt.show()

我得到这个散点图:

enter image description here

如果您想将其重叠到 map 上,请检查以下代码:
import matplotlib.pyplot as plt
import pandas as pd
from mpl_toolkits.basemap import Basemap
plt.style.use('seaborn-white')

df = pd.read_csv('data.csv')

colors = {'SUCS': 'red', 'ESCS': 'blue', 'SCS': 'green', 'D': 'black', 'VSCS': 'orange', 'DD': 'cyan', 'CS': 'magenta'}

fig, ax = plt.subplots(1, 1)

m = Basemap(llcrnrlon = 75, llcrnrlat = 5, urcrnrlon = 90, urcrnrlat = 20, resolution = 'i', projection = 'merc')
m.drawcoastlines(color = 'black')

df['x'], df['y'] = m(list(df['lon']), list(df['lat']))

for grade in list(df['grade'].unique()):
ax.scatter(df[df['grade'] == grade]['x'],
df[df['grade'] == grade]['y'],
s = 50,
label = grade,
facecolors = colors[grade])

plt.plot(df['x'], df['y'], 'k-', lw = 1)

plt.legend()
plt.show()

这给出了这张 map :

enter image description here

如果你想要一个更简单的解决方案,你可以用这个替换上面代码中的 for 循环:
import seaborn as sns
sns.scatterplot(data = df,
x = 'x',
y = 'y',
hue = 'grade',
s = 50)

关于python - 如何根据强度用标记颜色绘制气旋的轨迹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62282616/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com