python - 带有纬度和经度位置的熊猫数据框的轮廓
问题描述
我有一个包含 450 个位置的结果数据框。我想用 contourf 绘图,但似乎对以下代码有问题:
使用的数据框:
Results
</p>
WS Lat Lon
0 -8.394130 38.05 -102.62
1 -1.424622 40.05 -104.37
2 -10.795424 35.55 -108.87
3 -4.925160 36.55 -101.37
4 -5.485772 32.05 -102.62
... ... ... ...
445 -5.010812 44.55 -90.12
446 -3.847437 40.55 -93.87
447 -15.534713 47.55 -90.12
448 -5.306695 45.55 -96.87
449 -9.107669 43.05 -90.62
450 rows × 3 columns
绘图代码:
plt.figure(figsize=(15,12))
central_lat = 37.5
central_lon = -96
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
ax.add_feature(cfeature.STATES, linewidth=1.5,edgecolor='black')
cp = ax.contourf(Results["Lon"], Results["Lat"], Results["WS"],cmap=plt.cm.get_cmap('bwr', 22),levels=[-5,-4.5,-4,-3.5,-3,-2.5,-2,-1.5,-1,-0.5,0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5],alpha=0.6,transform = ccrs.PlateCarree(),extend='both')
cb=plt.colorbar(cp,orientation="horizontal",pad=0.1)
cb.set_label(label='Difference in long-term mean wind speed (%)',size='large')#, weight='bold')
# Define the xticks for longitude
ax.set_xticks(np.arange(-126,-65,10), crs=ccrs.PlateCarree())
lon_formatter = cticker.LongitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
# Define the yticks for latitude
ax.set_yticks(np.arange(25,51,5), crs=ccrs.PlateCarree())
lat_formatter = cticker.LatitudeFormatter()
ax.yaxis.set_major_formatter(lat_formatter)
我得到的错误:
TypeError:输入 z 必须是二维数组。
在这种情况下如何制作 za 2D 数组?我在数据框中有 450 个位置对。关于如何让它发挥作用的任何想法?
解决方案
推荐阅读
- assembly - 是否有任何官方文件证明 JL 和 JNGE 以相同的方式工作?
- javascript - 语义 UI 评级组件不工作 redux 表单
- python - 除非内核终止,否则 Jupyter/IPython 不会执行 with 语句
- javascript - JS - StreamSaver 下载不启动
- logstash - 我想通过logstash导入aws cloudtrail eventTime
- sql - 如何从sql中的“嵌套关系”中获取列值
- mysql - Mysql 中的默认值
- scala - 如何使用 Spark 为 sbt 多项目配置并行运行测试?
- reactjs - 使用简码将 React 应用程序集成到 wordpress 应用程序。为什么 React 路由不能正常工作?
- c# - Datagridview不要手动保留ColumnHeader设置