henry2004y / Batsrus.jl

BATSRUS/SWMF Data Processor
https://henry2004y.github.io/Batsrus.jl/dev/
MIT License
5 stars 2 forks source link

Equally spaced x values in Matplotlib `streamplot` #36

Closed henry2004y closed 4 months ago

henry2004y commented 9 months ago

For some outputs, drawing streamlines may end up with an error in Matplotlib

ValueError("'x' values must be equally spaced")
  File "C:\Users\hyzho\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\__init__.py", line 1461,

where the actual check in Matplotlib says

if not np.allclose(np.diff(x), self.width / (self.nx - 1)):
    raise ValueError("'x' values must be equally spaced")

A similar check in Julia would be

all(i -> isapprox(xrange[i+1] - xrange[i], (xrange[end] - xrange[1])/(length(xrange)-1)), eachindex(xrange)[1:end-1])

This is clearly a mismatch between Julia and Numpy, probably for Float32 numbers. Not a big deal, but the error messages are annoying. A quick workaround would be to set the plotinterval value together with plotrange.

henry2004y commented 4 months ago

This has already been fixed by using Float64 to construct ranges.