MakieOrg / GeoMakie.jl

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

xlims! error on GeoAxis #196

Closed jjgecon closed 8 months ago

jjgecon commented 8 months ago

I'm trying to set up a map with xlims!

where

lons = -180:180
lats = -90:90
field = [exp(cosd(l)) + 3(y/90) for l in lons, y in lats]

fig = Figure()
ax = GeoAxis(fig[1,1])
surface!(ax, lons, lats, field; shading = NoShading)
xlims!(ax,-90,90)
fig

gives the error MethodError: no method matching convert_limit_attribute(::Rect2{Float64})

I think there is an error in the source code makie-axis.jl because unlike ylims! (which work) have ax.finallimits[] in line 446 instead ax.limits[].

Zetison commented 8 months ago

Seems to be the same issue as #191

asinghvi17 commented 8 months ago

Try running this code and see if it works?

function Makie.xlims!(ax::GeoAxis, xlims)
    if length(xlims) != 2
        error("Invalid xlims length of $(length(xlims)), must be 2.")
    elseif xlims[1] == xlims[2] && xlims[1] !== nothing
        error("Can't set x limits to the same value $(xlims[1]).")
    elseif all(x -> x isa Real, xlims) && xlims[1] > xlims[2]
        xlims = reverse(xlims)
        ax.xreversed[] = true
    else
        ax.xreversed[] = false
    end
    mlims = Makie.convert_limit_attribute(ax.limits[])

    ax.limits.val = (xlims, mlims[2])
    Makie.reset_limits!(ax; yauto=false)
    return nothing
end

It's basically what you suggested @jjgecon :) - if this works will create a new patch release with these two fixes!