LSSTDESC / skyproj

Sky mapping with matplotlib and PROJ
BSD 3-Clause "New" or "Revised" License
11 stars 5 forks source link

axes text functions don't work for the axes transform #56

Open beckermr opened 8 months ago

beckermr commented 8 months ago

It appears that transAxes is actually the data coordinate system when it should be [0, 1] for the overall plot:

dtime = 1

d = footprint(BASELINE_SURVEY_START_MJD + dtime * YEAR, norm=False)

fig, axs = plt.subplots(figsize=(10, 6))

rmap = d["r"] * 0
rmap[wfd_idx] = d["r"][wfd_idx]

sp = skyproj.McBrydeSkyproj(ax=axs)
sp.draw_hpxmap(rmap, vmin=0, vmax=10, cmap="rocket_r")
sp.draw_colorbar(
    location="bottom", pad=0.15,
    label="requested cumulative visits normalized to 10 years",
)
sp.ax.text(
    170,
    90,
    "Year %0.2f" % dtime,
    ha="left",
    va="top",
    transform=sp.ax.transData,
    fontsize=16,
)

sp.ax.text(
    170,
    90,
    "Year %0.2f" % dtime,
    ha="left",
    va="top",
    transform=sp.ax.transAxes,
    fontsize=16,
    color="red",
)
erykoff commented 8 months ago

Oh this is a fun one. The problem isn't that transAxes is wrong. It's that I have an automatic override to always use the data transformation. This needs to be made more sophisticated.

erykoff commented 8 months ago

Oh it's actually easier than that. For the call to sp.ax.text it defaults to lonlat=True which says you want to specify positions as longitude/latitude. If you add lonlat=False to the last call then it'll work as expected. (Though you'll want to change 170, 90 or the text will go off into outer space).

beckermr commented 8 months ago

Ah ok. So this is where some of stuff we talked about on slack comes in. The mix of APIs here is confusing maybe or is that a known thing? That might just be me ofc. It's the counter intuitive patterns that don't match the MPL docs that make this tough.

erykoff commented 8 months ago

You can't use transData in one of these projections. You have to use sp.ax.projection as the transform. There's another layer of translation here, and that's the only way this works that I could figure out.

beckermr commented 8 months ago

🤯 this is so confusing. Why isn't transData mapped to projection?