散点图制作中的几个问题

2024-09-28 03:12:51 发布

您现在位置:Python中文网/ 问答频道 /正文

各位好,, 我试图通过在包含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


Tags: 代码mapdf轨迹绘制pltcslist
1条回答
网友
1楼 · 发布于 2024-09-28 03:12:51
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处画了一条线。因此,由于缩放,您缺少一个数据点

相关问题 更多 >

    热门问题