steveberardi / starplot

✨ Star charts and maps in Python
https://starplot.dev
MIT License
28 stars 8 forks source link

Constellation Labels not being inside the constellation boundaries #99

Open hemisemidemipresent opened 1 week ago

hemisemidemipresent commented 1 week ago

Sometimes, constellation labels will be awkwardly to a side (e.g. Hercules, Scutum, Corona Australis) and in some cases, just completely out of the boundary (e.g. Sagitta)

Also could there be labels for both Serpens (either duplicate Serpens labels or have one for Serpens cauda/caput)

image:

image

code:

from starplot import Star, DSO, MapPlot, Projection
from starplot.styles import PlotStyle, PolygonStyle, extensions

style = PlotStyle().extend(
    extensions.BLUE_LIGHT,
    extensions.MAP,
)
p = MapPlot(
    projection=Projection.MILLER,  # specify a non-perspective projection
    ra_min=14,  # limit the map to a specific area
    ra_max=22,
    dec_min=-45,
    dec_max=65,
    style=style,
    resolution=4000,
    hide_colliding_labels=False
)
p.gridlines() # add gridlines

p.stars(
    where=[Star.magnitude < 6],
    where_labels=[ (Star.magnitude < 3)],
    bayer_labels=True
)

p.constellations()
p.constellation_borders()
p.milky_way()
p.celestial_equator()
p.ecliptic()

p.export("test.png", padding=0.2, transparent=True)

Environment Details:

steveberardi commented 1 week ago

This is a known issue with constellation labels, and something I'm continually trying to improve. This one is tough because it's difficult to come up with a good foolproof way to automatically determine the best positions for labels (which can also change depending on how many objects you plot, the styles, etc). It's easier to do this for points (e.g. stars) cause the label has a much smaller range where it makes sense.

In early versions of Starplot, I just put the constellation label at the centroid of the constellation lines, which works well for some constellations but not all.

Anyway, hopefully I stumble upon a good solution soon. Open to any and all ideas!

hemisemidemipresent commented 1 week ago

How are constellation name labels position determined currently?

steveberardi commented 1 week ago

currently, the constellation label positions are hard-coded here -- these positions were originally calculated by finding the centroid of each constellation (can't remember if I did it by stars, or boundary) and then manually fine-tuning a bunch of them where the centroid wasn't a good place to put the label. This actually works pretty well for zenith projections, but not great for others (as you've discovered).