Skip to content

Commit

Permalink
STAR-26 / style adjustments (#107)
Browse files Browse the repository at this point in the history
* allow tuple

* allow tuples

* version

* polygon geometry

* format

* support python 39
  • Loading branch information
steveberardi authored Sep 22, 2024
1 parent d936a42 commit 0bb1186
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 33 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Adds colors for some DSO labels that were missing them in some style extensions
- Removed the kwarg `types` from `dsos`, so ALL DSO types are plotted by default
- [**v0.12.1**] Fixes issue with plotting the Milky Way when it consists of multiple polygons
- [**v0.12.2**] Allows tuples for line styles on polygons and adds geometry kwarg to polygon function

## v0.11.x
[Documentation](https://archives.starplot.dev/0.11.4/)
Expand Down
4 changes: 3 additions & 1 deletion docs/tutorial/09.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ title: 9 - Where to Go From Here
---
![Starplot](/images/favicon.svg){ align=right width="180" .off-glb }

**Congratulations on finishing the tutorial!** You're now a certified Level-1 Starplotter 🤩
**Congratulations on finishing the tutorial!**

You're now a certified Level-1 Starplotter 🤩

The purpose of the tutorial was just to give you an intro to some of Starplot's features, so there's more to explore by checking out the rest of the documentation. Here are some good places to check out next:

Expand Down
10 changes: 5 additions & 5 deletions hash_checks/hashlock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ map_gridlines:
filename: /starplot/hash_checks/data/map-gridlines.png
phash: f82acf9c3c616392
map_label_callables:
dhash: 80948c8c9c8c88a080988c8c9c8c88a0809c8d0d9d9c98a0
dhash: 80988c0c9c8c88a080988c0c9c8c88a0809a9d1d0d9d9aa0
filename: /starplot/hash_checks/data/map-m45-label-callables.png
phash: b26ccd99316664cd
phash: b238cdc92ce63699
map_milky_way_multi_polygon:
dhash: 351b89e4243a2604711b88e434322604751b88e424362624
filename: /starplot/hash_checks/data/map-milky-way-multi-polygon.png
phash: bc8bf89e90ce5a44
map_mollweide:
dhash: 0f2933632b3317070f2933632b3317070f295b6323130707
dhash: 0b2933632b3317070b2933632b3317070f295b6323130707
filename: /starplot/hash_checks/data/map-mollweide.png
phash: fa9af698c0259566
map_moon_phase_waxing_crescent:
Expand All @@ -43,9 +43,9 @@ map_plot_limit_by_geometry:
filename: /starplot/hash_checks/data/map-limit-by-geometry.png
phash: e54d9b926c6d1692
map_scope_bino_fov:
dhash: 0bc0808c8c8080802bceb2ac4daa928c2bceb2ac4daa928c
dhash: 0bc0808c8c8080802bc6b22d4da9928c2bc6b22d4da9928c
filename: /starplot/hash_checks/data/map-scope-bino-fov.png
phash: e46b296a6e693964
phash: e46b296e6e293964
map_stereo_base:
dhash: 627666f07c3c3436627666f0382c3436727666f2ecc89416
filename: /starplot/hash_checks/data/map-stereo-north-base.png
Expand Down
39 changes: 20 additions & 19 deletions hash_checks/map_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,35 +450,36 @@ def check_map_plot_custom_clip_path_virgo():


def check_map_label_callables():
style = STYLE.extend(
{
"dso_open_cluster": {
"label": {
"font_size": 28,
"font_weight": "bold",
"offset_x": 310,
"offset_y": 240,
}
},
}
)
p = MapPlot(
projection=Projection.MILLER,
ra_min=3.5,
ra_max=4,
dec_min=22,
dec_max=26,
style=STYLE.extend(
{
"dso_open_cluster": {
"label": {
"font_size": 28,
"font_weight": "bold",
"offset_x": 310,
"offset_y": 240,
}
},
}
),
style=style,
resolution=2000,
)
m45 = DSO.get(m="45")

p.open_clusters(
where=[
(DSO.magnitude.is_null()) | (DSO.magnitude < 12),
DSO.geometry.intersects(m45.geometry),
DSO.size > 0.08,
],
label_fn=lambda d: f"M{d.m}" if d.m else "",
p.polygon(
geometry=m45.geometry,
style__color=None,
style__fill_color=style.dso_open_cluster.marker.color,
style__edge_color="#000",
style__edge_width=4,
style__line_style=(0, (1.2, 8)),
)

p.stars(
Expand Down
2 changes: 1 addition & 1 deletion src/starplot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Star charts and maps"""

__version__ = "0.12.1"
__version__ = "0.12.2"

from .base import BasePlot # noqa: F401
from .map import MapPlot, Projection # noqa: F401
Expand Down
20 changes: 18 additions & 2 deletions src/starplot/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from matplotlib import pyplot as plt, patheffects
from matplotlib.lines import Line2D
from pytz import timezone
from shapely import Polygon

from starplot import geod, models
from starplot.data import load, ecliptic
Expand Down Expand Up @@ -498,13 +499,28 @@ def _polygon(self, points: list, style: PolygonStyle, **kwargs):
self.ax.add_patch(patch)

@use_style(PolygonStyle)
def polygon(self, points: list, style: PolygonStyle):
"""Plots a polygon of points
def polygon(
self,
style: PolygonStyle,
points: list = None,
geometry: Polygon = None,
):
"""
Plots a polygon.
Must pass in either `points` **or** `geometry` (but not both).
Args:
points: List of polygon points `[(ra, dec), ...]` - **must be in counterclockwise order**
geometry: A shapely Polygon. If this value is passed, then the `points` kwarg will be ignored.
style: Style of polygon
"""
if points is None and geometry is None:
raise ValueError("Must pass points or geometry when plotting polygons.")

if geometry is not None:
points = list(zip(*geometry.exterior.coords.xy))

_points = [(ra * 15, dec) for ra, dec in points]
self._polygon(_points, style)

Expand Down
11 changes: 6 additions & 5 deletions src/starplot/styles/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from enum import Enum
from pathlib import Path
from typing import Optional
from typing import Optional, Union
from functools import cache

import yaml
Expand Down Expand Up @@ -332,8 +332,8 @@ class LineStyle(BaseStyle):
color: ColorStr = ColorStr("#000")
"""Color of the line. Can be a hex, rgb, hsl, or word string."""

style: LineStyleEnum = LineStyleEnum.SOLID
"""Style of the line (e.g. solid, dashed, etc)."""
style: Union[LineStyleEnum, tuple] = LineStyleEnum.SOLID
"""Style of the line (e.g. solid, dashed, etc). Can be a predefined value in `LineStyleEnum` or a [Matplotlib linestyle tuple](https://matplotlib.org/stable/gallery/lines_bars_and_markers/linestyles.html)."""

dash_capstyle: DashCapStyleEnum = DashCapStyleEnum.PROJECTING
"""Style of dash endpoints"""
Expand Down Expand Up @@ -401,8 +401,8 @@ class PolygonStyle(BaseStyle):
fill_color: Optional[ColorStr] = None
"""Fill color of the polygon"""

line_style: LineStyleEnum = LineStyleEnum.SOLID
"""Edge line style"""
line_style: Union[LineStyleEnum, tuple] = LineStyleEnum.SOLID
"""Edge line style. Can be a predefined value in `LineStyleEnum` or a [Matplotlib linestyle tuple](https://matplotlib.org/stable/gallery/lines_bars_and_markers/linestyles.html)."""

alpha: float = 1.0
"""Alpha value (controls transparency)"""
Expand All @@ -419,6 +419,7 @@ def matplot_kwargs(self, size_multiplier: float = 1.0) -> dict:
linestyle=self.line_style,
alpha=self.alpha,
zorder=self.zorder,
capstyle="round",
)
if self.color:
styles["color"] = self.color.as_hex()
Expand Down

0 comments on commit 0bb1186

Please sign in to comment.