MakieOrg / GeoMakie.jl

Geographical plotting utilities for Makie.jl
https://geo.makie.org
MIT License
173 stars 25 forks source link

Plotting artifact with longitudes ranging from 0 to 360 degrees? #290

Open ph-kev opened 1 week ago

ph-kev commented 1 week ago

I am not sure if this is an issue or if it is not supported by GeoMakie, but plotting data where the longitude ranges from 0 to 360 degrees differ from the same data ranging from -180 degrees to 180 degrees.

I am using landsea.nc from https://www.ncl.ucar.edu/Applications/Data/#cd and I ran the following script

using NCDatasets
using CairoMakie
using GeoMakie

# Get longitudes, latitudes, and mask data
nc = NCDataset("landsea.nc")
lat = nc["lat"][:]
lon = nc["lon"][:]
mask = nc["LSMASK"][:, :]

# Plot with longitudes ranging from 0 to 360 degrees
fig = Figure()
ax = GeoAxis(fig[1,1])
contourf!(ax, lon, lat, mask)
display(fig)

# Change longitudes to range from -180 to 180 degrees
lon[lon .> 180] .-= 360
sort_idx = sortperm(lon)
lon = lon[sort_idx]
mask = mask[sort_idx, :]

# Plot with longitudes ranging from -180 to 180 degrees
fig = Figure()
ax = GeoAxis(fig[1,1])
contourf!(ax, lon, lat, mask)
display(fig)

I get the following two images: Image Image

The second image is what I expected, but the first image is off. There is distortion at the top and bottom of the plot.

asinghvi17 commented 6 days ago

Yeah, the first image is because Makie doesn't know how to wrap those coordinates around yet. It's a hard issue to solve since it needs changes through the whole plotting stack. But we'll probably get there at some point.

For now the solution you found is likely the best one.