Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23276

Plotting density plots with Cartopy resulting in a problem around discontinuity

$
0
0

I plotted the cyclone density data on a Cartopy NorthPolarStereo projection, but there is an obvious shift in the density around the discontinuity. This discontinuity is here because of the lack of data. I assume that this is because of the transforming of the data grid onto a Cartopy grid, but not sure how to solve it.

Here is the plot:

Here is the plot:

Here is the code:

import numpy as npfrom scipy.ndimage import gaussian_filterimport matplotlib.pyplot as pltlat1 = 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 Differencetotal_difference = hist_smooth1 - hist_smooth2density_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 differencecbar_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 plotplt.savefig('Cyclone Track Total Difference', dpi='figure', format='png')plt.show()plt.close()

Viewing all articles
Browse latest Browse all 23276

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>