Healpix.jl
Healpix.jl copied to clipboard
Annotating with Plots.jl or Makie.jl - getting the text coordinates right
I am having trouble to find out how to get the pixel coordinates for a given angle.
julia> using Plots
[ Info: Precompiling Plots [91a5bcdd-55d7-5caf-9e0b-520d859cae80]
julia> m = HealpixMap{Float64, RingOrder}(32);
julia> m[ang2pixRing(m.resolution, π/4, 0.0)] = 250
250
julia> m[ang2pixRing(m.resolution, 0.42, 0.23)] = 300
300
julia> plot(m)
julia> annotate!(π/4, 0.0, "some text")
Here, obviously annotate!
is not printed in the coordinate system of the plot. I found ang2pix
but that only gives the pixel number. How can I find the "plot coordinate" for a given angle or vector?
Hi @tamasgal , unfortunately Healpix.jl is not as sophisticated as Healpy when producing plots. Basically, when you plot a map there is a small raytracer (see the project function) that trace rays and find where they hit the unitary sphere according to the inverse projection function (which converts a 2D point x,y into a 3D direction θ,φ).
Thus, the output plot produced by Plots.jl has no knowledge of the coordinate transformation that was done internally by Healpix.jl. Thus, your annotate!
call interprets the (x,y) point in the 2D space of the window and not in the 3D space of the surface of the sphere 🙁.
Implementing proper coordinate conversions would be a very welcomed PR. However, I do not know the amount of support for coordinate transformations provided by Plots.jl. Perhaps it would be better to provide a plotting backend for Healpix.jl based on Makie.jl: judging from some demos I've seen, it might be that it is perfectly capable of doing this.
Yes that's what I also understood.
Well I used Plots.jl
because there was a recipe but I would definitely prefer Makie.jl
;)
It's actually not that complicated to display a similar plot in Makie.jl
:
img, mask, anymasked = mollweide(m, Dict()) # m is a HealpixMap like above
fig = Figure(size = (1800, 900))
ax = CairoMakie.Axis(fig[1, 1], aspect = 2)
hidedecorations!(ax)
heatmap!(ax, img', show_axis = false)
hidespines!(ax)
fig
gives
So now back to the original problem of transforming the coordinates but in Makie.jl
;) I'll come back if I have some news.