制作散点图时的问题

问题描述 投票:0回答:1

大家好, 我试图通过在包含sst的空间图上使用散点图来显示热带气旋的轨迹。现在,在绘制轨迹时,散点图似乎并没有绘制所有图,主要是在陆地上看到它未绘制点。我无法指出我的代码在哪里做错了,如果有人可以在这方面提供帮助,将不胜感激。我要发布代码的一部分以及lat long值和生成的图。我将lat long数据作为文本提供,如下所示:

Lat Lon grade
10.4 87 D
10.9 86.3 D
10.9 86.3 CS
11.1 86.1 CS
11.4 86 CS
11.5 86 SCS
12 86 VSCS
12.5 86.1 VSCS
13.2 86.3 ESCS
13.4 86.2 SuCS
14   86.3 SuCS
14.9 86.5 SuCS
15.6 86.7 SuCS
16.5 86.9 ESCS
17.4 87 ESCS
18.4 87.2 ESCS
19.1 87.5 ESCS
20.6 88 ESCS
21.9 88.4 VSCS
23.3 89 SCS
24.2 89.3 CS
25 89.6 DD
25.4 89.6 D



cs=map.contourf(x,y,plt_data,clevels,cmap=plt.cm.jet)#,clevels,cmap=plt.cm.jet)
    map.colorbar(cs)

df = pd.read_excel('E:/bst_trc.xls',sheet_name='Sheet6')
colors = {'SuCS': 'red', 'ESCS': 'blue', 'SCS': 'green', 'D': 'black', 'VSCS': 'orange', 'DD':'cyan', 
              'CS': 'magenta'}

df['x'], df['y'] = map(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.5)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05),
      fancybox=True, shadow=True, ncol=7)
#plt.savefig('E:/Super_cyclone/Amphan/sst_bfr.tif', bbox_inches='tight', dpi=300)
plt.show()

enter image description here

enter image description here

python python-3.x matplotlib data-visualization scatter-plot
1个回答
0
投票
grade_unique = df['grade'].unique()
grade_unique

colormap = {a:b/len(grade_unique) for b,a in enumerate(grade_unique)}

df['color'] = df['grade'].replace(colormap)

plt.plot(df['Lon'], df['Lat'], c='k')
plt.scatter(df['Lon'], df['Lat'], c=df['color'], cmap='magma')

plt.hlines(y=25,xmin=0,xmax=100, linestyles='dashed')

plt.ylim(5,30)
plt.xlim(75,95)

enter image description here

绘制您提供的数据即可得到。我重新缩放以将所有数据点都绘制到绘图上,并在ylimit的上限处画了一条线。因此,由于缩放,您缺少一个数据点。

© www.soinside.com 2019 - 2024. All rights reserved.