Giter Club home page Giter Club logo

Comments (2)

dsroberts avatar dsroberts commented on June 15, 2024 1

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.
044
try_plot(-4.44e-16)
000
try_plot(0)
050
try_plot(-5e-16)
040
try_plot(-4e-16)
045
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?

from cartopy.

rcomer avatar rcomer commented on June 15, 2024

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:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import numpy as np
import netCDF4

ds = netCDF4.Dataset('dataset.nc','r')

def try_plot(lev0):
    ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=1))
    cf = ax.contourf(np.array(ds['lon']), np.array(ds['lat']), np.array(ds['a']), transform=ccrs.PlateCarree(), levels=[lev0, lev0+0.2], extend='both')
    plt.colorbar(cf)
    plt.show()


try_plot(-4.44e-16)
try_plot(0)

The slightly negative value give this (bad!)
image

Whereas zero give this (good!)
image

A workaround for your researcher might be to use levels=np.linspace(-2, 2, 21), which gives me this:

image

from cartopy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.