Skip to content

Commit

Permalink
_add_polar_y_ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
dhimmel committed Jan 18, 2025
1 parent 73aa4c6 commit 717dc8a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 44 deletions.
31 changes: 31 additions & 0 deletions openskistats/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,37 @@ def _plot_mean_bearing_as_snowflake(
)


def _add_polar_y_ticks(
ax: PolarAxes,
arc_center: float = 225.0,
arc_width: float = 10.0,
arc_color: str = "white",
) -> None:
# y-tick labeling
y_ticks = np.arange(0, 91, 10)
ax.set_yticks(y_ticks)
# ax.tick_params(axis="y", which="major", length=5, width=1)
ax.set_yticklabels(
[f"{r}°" if r in {0, 90} else "" for r in y_ticks],
rotation=0,
fontsize=7,
color=arc_color,
)
ax.set_rlabel_position(arc_center)
# Draw custom radial arcs for y-ticks
for radius in y_ticks:
theta_start = np.deg2rad(arc_center - arc_width / 2)
theta_end = np.deg2rad(arc_center + arc_width / 2)
theta = np.linspace(theta_start, theta_end, 100)
ax.plot(
theta,
np.full_like(theta, radius),
linewidth=1 if radius < 90 else 2,
color=arc_color,
)
ax.set_rlim(0, 90)


def subplot_orientations(
groups_pl: pl.DataFrame,
grouping_col: str,
Expand Down
25 changes: 2 additions & 23 deletions openskistats/plot_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
get_cut_bearing_bins_df,
)
from openskistats.models import SkiRunDifficulty
from openskistats.plot import NARROW_SPACE
from openskistats.plot import NARROW_SPACE, _add_polar_y_ticks
from openskistats.utils import (
pl_condense_run_difficulty,
pl_flip_bearing,
Expand Down Expand Up @@ -275,28 +275,7 @@ def plot_bearing_by_latitude_bin() -> plt.Figure:
xticklabels = ["Poleward", "", "E", "", "Equatorward", "", "W", ""]
ax.set_xticklabels(labels=xticklabels)
ax.tick_params(axis="x", which="major", pad=-2)
# y-tick labeling
latitude_ticks = np.arange(0, 91, 10)
ax.set_yticks(latitude_ticks)
ax.tick_params(axis="y", which="major", length=5, width=1)
ax.set_yticklabels(
[f"{r}°" if r in {0, 90} else "" for r in latitude_ticks],
rotation=0,
fontsize=7,
)
ax.set_rlabel_position(225)

# Draw custom radial arcs for y-ticks
for radius in latitude_ticks:
theta_start = np.deg2rad(220)
theta_end = np.deg2rad(230)
theta = np.linspace(theta_start, theta_end, 100)
ax.plot(
theta,
np.full_like(theta, radius),
linewidth=1 if radius < 90 else 2,
color="black",
)
_add_polar_y_ticks(ax=ax, arc_color="black")

return fig

Expand Down
30 changes: 9 additions & 21 deletions openskistats/sunlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def plot(self) -> plt.Figure:
slope_grid,
irradiance_grid,
shading="nearest",
cmap="coolwarm",
cmap="inferno",
)
colorbar = plt.colorbar(quad_mesh, ax=ax, location="left", aspect=35, pad=0.053)
colorbar.outline.set_visible(False)
Expand All @@ -447,15 +447,9 @@ def plot(self) -> plt.Figure:
ax.set_xticklabels(labels=xticklabels)
ax.tick_params(axis="x", which="major", pad=-2)
# y-tick labeling
slope_ticks = np.arange(0, 60, 10)
ax.set_yticks(slope_ticks)
ax.tick_params(axis="y", which="major", length=5, width=1)
ax.set_yticklabels(
[f"{r}°" if r in {0, 50} else "" for r in slope_ticks],
rotation=0,
fontsize=7,
)
ax.set_rlabel_position(225)
from openskistats.plot import _add_polar_y_ticks

_add_polar_y_ticks(ax=ax)
return fig


Expand Down Expand Up @@ -508,13 +502,14 @@ def get_grids(

def plot(self) -> plt.Figure:
latitude_grid, bearing_grid, irradiance_grid = self.get_grids()
# can use _get_fig_ax to support existing subplots
fig, ax = plt.subplots(subplot_kw={"projection": "polar"})
quad_mesh = ax.pcolormesh(
np.deg2rad(bearing_grid),
latitude_grid,
irradiance_grid.transpose(),
shading="nearest",
cmap="viridis",
cmap="inferno",
)
colorbar = plt.colorbar(quad_mesh, ax=ax, location="left", aspect=35, pad=0.053)
colorbar.outline.set_visible(False)
Expand All @@ -527,14 +522,7 @@ def plot(self) -> plt.Figure:
xticklabels = ["N", "", "E", "", "S", "", "W", ""]
ax.set_xticklabels(labels=xticklabels)
ax.tick_params(axis="x", which="major", pad=-2)
# y-tick labeling
slope_ticks = np.arange(0, 60, 10)
ax.set_yticks(slope_ticks)
ax.tick_params(axis="y", which="major", length=5, width=1)
ax.set_yticklabels(
[f"{r}°" if r in {0, 50} else "" for r in slope_ticks],
rotation=0,
fontsize=7,
)
ax.set_rlabel_position(225)
from openskistats.plot import _add_polar_y_ticks

_add_polar_y_ticks(ax=ax)
return fig

0 comments on commit 717dc8a

Please sign in to comment.