I’m trying to plot weather data from a Numpy array (precipitation in this example) in matplot using a filled contour. I am currently having issues with missing data and lines at the edge of data values. I suspect this is related to the figure size and resolution of the plot not matching the source array – I’d like each pixel to represent one point in the array but I’m not sure how to accomplish this.
You can see the areas where there is no data in the attached image (this is actually a crop of a compressed image, ignore the compression artifacts, same thing happens with a png) as well as contour lines where none should be at the edge of a value. I’ve verified this doesn’t match the source array (there are no gaps).
Changing the antialiasing to true did not seem to help. Relevant code is below:
imageRes = 50
aspectRatio = 1.5
plotProj = ccrs.PlateCarree() # from cartopy
fig,ax = plt.subplots(ncols=1,
nrows=1,
subplot_kw={'projection':self.plotProj, 'aspect':self.aspectRatio},
dpi=self.imageRes,
figsize=(imageSettings.heicImageWidth/self.imageRes,
imageSettings.heicImageHeight/self.imageRes))
fig.patch.set_visible(False)
ax.contourf(lon,lat,item,vmin=minValue,vmax=maxValue, extend='max', transform=self.plotProj,colors=colors[index], levels=levels[index], hatches=hatches[index], antialiased=False)
ax.set_extent([-125.0,-66.0, 24.0, 54.0], crs=self.plotProj)
ax.axis('off')
plt.savefig(buffer, pad_inches=0, bbox_inches="tight", transparent=True, dpi=self.imageRes)
img = img.resize((int(imageSettings.heicImageWidth), int(imageSettings.heicImageHeight)), resample = Image.LANCZOS)
img.save(outputFilename, quality = imageSettings.heicImageQuality)