Below is my code. No matter what I tried. I can only get the degree symbol “°” displayed, but not the N or W next to it. Does anyone know how to do it properly?
using CairoMakie
using GeoMakie
# Create figure and geographical axis with correct projection settings
Han = Figure();
ga = GeoAxis(Han[1, 1];
source = "+proj=longlat +datum=WGS84", # Input CRS (WGS84 lat/lon)
dest = "+proj=moll +lat_0=45 +lon_0=-100",
xticks = -180:30:-30,
yticks = 10:10:80,
xtickformat = xs -> [@sprintf("%.0f°", abs(x), x < 0 ? "W" : "E") for x in xs],
ytickformat = ys -> [@sprintf("%.0f°", abs(y), y < 0 ? "S" : "N") for y in ys]
);
# Add coastlines:
lines!(ga, GeoMakie.coastlines(); color = :black)
The above code errors for me because it provides two arguments to a format string accepting only one. You need the format to specify a second argument. In this case, you want a string argument %s:
julia> using Printf
julia> x = -6.0; @sprintf("%.0f°", abs(x), x < 0 ? "W" : "E")
ERROR: ArgumentError: Number of format specifiers and number of provided args differ: 1 != 2
julia> x = -6.0; @sprintf("%.0f°%s", abs(x), x < 0 ? "W" : "E")
"6°W"
Many thanks! However, it still does not work for me. Here is my new parameters verbatim:
xtickformat = xs -> [@sprintf("%.0f°%s", abs(x), x < 0 ? "W" : "E") for x in xs],
ytickformat = ys -> [@sprintf("%.0f°%s", abs(y), y < 0 ? "S" : "N") for y in ys]
Be more specific. What does “not work for me” mean? It errors? It runs but the labels aren’t what you expect?
With a normal Makie Axis the above works for me. When I run your version or one of GeoMakie’s demos with GeoAxis the labels are unchanged. So I’m guessing that’s your issue.
It seems that GeoMakie is not respecting the _tickformat arguments. What’s strange is that GeoMakie has code for making ticks like this already but it doesn’t appear to be used anywhere and I’m not familiar enough with the package to understand how to make it be used. It appears that these were used in older versions, as seen in examples in older issues like this one.
It seems that you could open an issue on GeoMakie.
Go to GeoMakie’s issue tracker on GitHib, check to see if there’s already an issue for this (I didn’t see one), log in, select [New issue]. Then state what version of GeoMakie and Makie/CairoMakie you’re using, describe what happens versus what you expect to happen, and provide runnable code that reproduces the issue (start a fresh REPL and make sure it runs with the result you say).