使用 Cartopy 绘制密度图会导致不连续性问题

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

我在

Cartopy NorthPolarStereo
投影上绘制了气旋密度数据,但不连续性周围的密度存在明显的变化。由于缺乏数据,出现这种不连续性。我认为这是因为将数据网格转换为
Cartopy
网格,但不知道如何解决它。

剧情如下:

Here is the plot:

这是代码:

import numpy as np
from scipy.ndimage import gaussian_filter
import matplotlib.pyplot as plt

lat1 = df1['xlat']
lon1 = df1['xlon']

lat2 = df2['xlat']
lon2 = df2['xlon']


bins1 = [np.linspace(lon1.min(), lon1.max(), 100), np.linspace(lat1.min(), lat1.max(), 100),]
hist1, xedges1, yedges1 = np.histogram2d(lon1, lat1, bins=bins1)

bins2 = [np.linspace(lon2.min(), lon2.max(), 100), np.linspace(lat2.min(), lat2.max(), 100),]
hist2, xedges2, yedges2 = np.histogram2d(lon2, lat2, bins=bins2)
    
hist_smooth1 = gaussian_filter(hist1, sigma=2)
hist_smooth2 = gaussian_filter(hist2, sigma=2)

fig, axs_total_difference = plt.subplots(1, 1, subplot_kw={'projection': ccrs.NorthPolarStereo(central_longitude=0.0, globe=None)}, figsize=(10, 7))

# Plot - Total Difference
total_difference = hist_smooth1 - hist_smooth2
density_total_difference = axs_total_difference.contourf(xedges1[:-1], yedges1[:-1], total_difference.T, transform=ccrs.PlateCarree(), cmap='bwr')
axs_total_difference.set_title('Total Difference (ERA5 - ICON)')

axs_total_difference.add_feature(cartopy.feature.OCEAN, color='white', zorder=0)
axs_total_difference.add_feature(cartopy.feature.LAND, color='lightgray', zorder=0, linewidth=0.5, edgecolor='black')
axs_total_difference.gridlines(draw_labels=True, linewidth=0.5, color='gray', xlocs=range(-180, 180, 15), ylocs=range(-90, 90, 15), x_inline=False, y_inline=False)
axs_total_difference.coastlines(resolution='50m', linewidth=0.3, color='black')

# Colorbar for total difference
cbar_ax_total = plt.gcf().add_axes([0.92, 0.15, 0.02, 0.7])  
cbar_total = plt.colorbar(density_total_difference, cax=cbar_ax_total)
cbar_total.set_label('Total Difference')

# Save or show the plot
plt.savefig('Cyclone Track Total Difference', dpi='figure', format='png')
plt.show()
plt.close()

python plot cartopy
1个回答
0
投票

添加循环数据并利用它来制作全覆盖图的步骤。 (基于@Ruthc提供的链接)

# 导入工具:
导入 cartopy.util 作为 cutil
# 获取修改后的数据集:
cdata, clon, clat = cutil.add_circular(total_difference.T, xedges1[:-1], yedges1[:-1])
# 使用修改后的数据集创建填充轮廓
Density_total_difference = axs_total_difference.contourf(clon, clat, cdata, 变换=ccrs.PlateCarree(), cmap='bwr')
© www.soinside.com 2019 - 2024. All rights reserved.