You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In some very specific circumstances, negative contours will not be shown, and some odd contours are shown in a contourf plot. The code below demonstrates the issue, but the issue is not present when the central_longitude argument to projection=ccrs.PlateCarree() is 0 or removed, or when the contour levels are not centered around 0 or extended beyond levels=np.arange(-4,4.4,0.4). The researcher I'm helping with this has 3 other similar contourf plots (same levels, central_longitude=180) that don't have this issue. The issue is present in the latest cartopy 0.22.0 conda-forge release, and in the current main branch, though only present for Matplotlib >= 3.8. Example plots are below:
Cartopy main, matplotlib 3.8.3, central_longitude=0
Cartopy main, matplotlib 3.8.3, central_longitude=1
Cartopy main, matplotlib 3.7.5, central_longitude=1
Looking through some of the other contourf based issues, this one seems similar to #2288, #1822 and #1076, but distinct in some way from all of those.
Code to reproduce
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import numpy as np
import netCDF4
ds = netCDF4.Dataset('dataset.nc','r')
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=1))
ax.contourf(np.array(ds['lon']),np.array(ds['lat']),np.array(ds['a']),transform=ccrs.PlateCarree(),levels=np.arange(-2,2.2,0.2),extend='both')
plt.show()
Thanks for the report and the clear reproducer @dsroberts. This seems reminiscent of #2224 which I ultimately solved by locating the specific problem level and analyzing that. I had some trouble locating the problem level in this case as it seems to be very specific to the slightly off-zero value generated by arange. But now I have this:
Thanks for looking into this @rcomer. I will pass your recommendation on. I played around with your try_plot function and got some interesting results. The resultant contours are extremely sensitive to that central value. try_plot(-4.44e-16) try_plot(0) try_plot(-5e-16) try_plot(-4e-16) try_plot(-4.5e-16)
I also added lev0 to the data (after casting it to float64) which would align the 'zeros' in the data with the middle level, and this resulted in 5 identical plots. I guess this would indicate a floating point conversion and/or equality error somewhere?
Description
In some very specific circumstances, negative contours will not be shown, and some odd contours are shown in a contourf plot. The code below demonstrates the issue, but the issue is not present when the
central_longitude
argument toprojection=ccrs.PlateCarree()
is 0 or removed, or when the contour levels are not centered around 0 or extended beyondlevels=np.arange(-4,4.4,0.4)
. The researcher I'm helping with this has 3 other similar contourf plots (same levels,central_longitude=180
) that don't have this issue. The issue is present in the latest cartopy 0.22.0 conda-forge release, and in the currentmain
branch, though only present for Matplotlib >= 3.8. Example plots are below:Cartopy
main
, matplotlib 3.8.3,central_longitude=0
Cartopy
main
, matplotlib 3.8.3,central_longitude=1
Cartopy
main
, matplotlib 3.7.5,central_longitude=1
Looking through some of the other contourf based issues, this one seems similar to #2288, #1822 and #1076, but distinct in some way from all of those.
Code to reproduce
With dataset.nc.gz
Full environment definition
Operating system
linux-64
Cartopy version
0.22.1.dev109+g36eb99ef
pip list
The text was updated successfully, but these errors were encountered: