-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Observable to adjust colorbar height crashes with GeoMakie
but not GLMakie
#135
Comments
I seem to slip up with the same gotcha every time I do prototypes: don't use If I use julia> using GeoMakie, GLMakie
julia> fig = Figure()
julia> ga = GeoAxis(fig[1,1]);
julia> sf = surface!(ga, -180:180, -90:90, rand(361, 181));
julia> Colorbar(fig[1,2], sf, height = @lift Fixed($(pixelarea(ga.scene)).widths[2])) the code doesn't crash, but it is made very very small: If I try to use the projection julia> fig = Figure()
julia> ga = GeoAxis(fig[1,1]; dest = "+proj=eqc");
julia> sf = surface!(ga, -180:180, -90:90, rand(361, 181));
julia> Colorbar(fig[1,2], sf, height = @lift Fixed($(pixelarea(ga.scene)).widths[2]))
ERROR: StackOverflowError:
[...] the call to |
With this code: julia> using GeoMakie, GLMakie
julia> fig = Figure()
ga
julia> ga = GeoAxis(fig[1,1]; dest = "+proj=eqc");
julia> sf = surface!(ga, -180:180, -90:90, rand(361, 181));
julia> obs = @lift Fixed($(pixelarea(ga.scene)).widths[2])
Observable(Fixed(762.0f0))
# before this call, I resized the plot window with my cursor to make it bigger
julia> obs
Observable(Fixed(1154.0f0))
# Adding a fixed-size colorbar (with default height) usually works
julia> Colorbar(fig[1,2], sf);
julia> Colorbar(fig[1,3], sf, height = obs)
ERROR: StackOverflowError:
[...] I was once able to get the resizing to work, but now I am unable to reproduce that, and I get |
I have a very rudimentary understanding of julia> fig = Figure()
julia> ga = GeoAxis(fig[1,1]; dest = "+proj=eqc");
# julia> ga = GeoAxis(fig[1,1]) # works with default projection too
julia> obs = @lift Fixed($(pixelarea(ga.scene)).widths[2]) # fetch plot height
Observable(Fixed(362.0f0))
# This is not needed for fixing the Colorbar, but shows the current figure height as an axis title -->
julia> tobs = @lift "figure height: $(string($obs)[7:end-3])" # dirty hack to get the number part of the string "Fixed(362.0f0)"
Observable("figure height: 362.0")
julia> ga.title[] = tobs.val # set initial title
"figure height: 362.0"
julia> on(tobs) do t # update title when plot pane is resized
ga.title = t
end
ObserverFunction defined at REPL[247]:2 operating on Observable("figure height: 361.0")
# <--
julia> sf = surface!(ga, -180:180, -90:90, rand(361, 181));
julia> rowsize!(fig.layout, 1, Auto(false)) # This is the critical part of the code
julia> Colorbar(fig[1,2], sf, height = obs)
Colorbar() The critical component is the call to
i.e.: The vertical size of the plot (≤ height of |
Looking at the julia> using GeoMakie, GLMakie
julia> fig = Figure()
julia> ga = GeoAxis(fig[1,1])#; dest = "+proj=eqc");
julia> obs = @lift $(pixelarea(ga.scene)).widths[2]
# For title --->
julia> tobs = @lift "plot height: $($obs)"
julia> ga.title[] = tobs.val
julia> on(tobs) do t
ga.title = t
end
# <---
julia> sf = surface!(ga, -180:180, -90:90, rand(361, 181));
julia> rowsize!(fig.layout, 1, Auto(false)) # This is the critical part of the code
julia> Colorbar(fig[1,2], sf, height = obs) A very similar code can be used to have a horizontal colorbar under the figure: See details for horizontal colorbarjulia> using GeoMakie, GLMakie
julia> fig = Figure()
julia> ga = GeoAxis(fig[1,1])#; dest = "+proj=eqc");
julia> obs = @lift $(pixelarea(ga.scene)).widths[1] # fetch the first element of .widths instead of the second.
# For title --->
julia> tobs = @lift "plot width: $($obs)"
julia> ga.title[] = tobs.val
julia> on(tobs) do t
ga.title = t
end
# <---
julia> sf = surface!(ga, -180:180, -90:90, rand(361, 181));
julia> colsize!(fig.layout, 1, Auto(false)) # use colsize! instead of rowsize!
julia> Colorbar(fig[2,1], sf, vertical=false, width = obs) # set vertical to false, and specify width instead of height.
# set `flipaxis=false` to get ticks and ticklabels below colorbar |
I am trying to make a colorbar for a plot that adjusts to the height of the figure. Following MakieOrg/Makie.jl#1874 (comment), with GLMakie I can do:
which produces the desired output:
However, if I do essentially the same with GeoMakie:
I get either this error:
ERROR: AssertionError: length(positions) == length(labels)
or this error:
ERROR: StackOverflowError:
OS details:
any suggestions?
The text was updated successfully, but these errors were encountered: