Skip to content

Commit

Permalink
sunlight plots axis labels
Browse files Browse the repository at this point in the history
  • Loading branch information
dhimmel committed Jan 21, 2025
1 parent 93e2127 commit 5b54ac0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
31 changes: 30 additions & 1 deletion openskistats/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,34 @@ def _add_polar_y_ticks(
arc_center: float = 225.0,
arc_width: float = 10.0,
arc_color: str = "white",
title: str | None = None,
) -> None:
"""Add radial ticks and optional title to polar plot.
Parameters
----------
ax : PolarAxes
The matplotlib polar axes to add ticks to
arc_center : float
Center angle in degrees for the tick arcs
arc_width : float
Width of the tick arcs in degrees
arc_color : str
Color for the ticks and labels
title : str | None
Optional title for the radial axis
"""
# 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)
Expand All @@ -345,6 +361,19 @@ def _add_polar_y_ticks(
)
ax.set_rlim(0, 90)

# Add radial axis title if provided
if title:
ax.text(
x=np.deg2rad(270),
y=45,
s=title,
rotation=0,
color=arc_color,
fontsize=10,
ha="center",
va="center",
)


def subplot_orientations(
groups_pl: pl.DataFrame,
Expand Down
18 changes: 12 additions & 6 deletions openskistats/sunlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,13 @@ def _setup_polar_plot(self, ax: plt.Axes, colorbar: bool = True) -> Colorbar | N

from openskistats.plot import _add_polar_y_ticks

_add_polar_y_ticks(ax=ax)
_add_polar_y_ticks(
ax=ax,
arc_center=315,
arc_width=10,
arc_color="white",
title="Slope" if isinstance(self, SlopeByBearingPlots) else "Latitude",
)

cb = None
if colorbar:
Expand Down Expand Up @@ -616,7 +622,7 @@ def get_grids(
def create_combined_solar_plots() -> plt.Figure:
"""Create a combined figure with multiple solar plots arranged in a 2x3 grid."""
# Create main figure with two subfigures side by side
fig = plt.figure(figsize=(17, 10), constrained_layout=True)
fig = plt.figure(figsize=(9.5, 5), constrained_layout=True)
subfigs = fig.subfigures(nrows=1, ncols=2, width_ratios=[2, 1])

# Left subfigure for instant irradiance plots (4 plots)
Expand Down Expand Up @@ -652,20 +658,20 @@ def create_combined_solar_plots() -> plt.Figure:
_, mesh1 = plotters[0].plot(fig=fig, ax=ax1, vmax=max_value_instant)
ax1.set_title("Winter Solstice Morning")
_, mesh2 = plotters[1].plot(fig=fig, ax=ax2, vmax=max_value_instant)
ax2.set_title("Season Close Afternoon")
ax2.set_title("Closing Day Afternoon")
_, mesh4 = plotters[3].plot(fig=fig, ax=ax4, vmax=max_value_instant)
_, mesh5 = plotters[4].plot(fig=fig, ax=ax5, vmax=max_value_instant)

# Plot season average plots
_, mesh3 = plotters[2].plot(fig=fig, ax=ax3, vmax=max_value_season)
ax3.set_title("Season Average")
ax3.set_title("Entire Season")
_, mesh6 = plotters[5].plot(fig=fig, ax=ax6, vmax=max_value_season)

# Add colorbars to each subfigure
subfig_instant.colorbar(
mesh1,
ax=[ax1, ax2, ax4, ax5],
label="Instant Irradiance (W/m²)",
label="Instantaneous Irradiance (W/m²)",
location="right",
pad=0.05,
aspect=40,
Expand All @@ -674,7 +680,7 @@ def create_combined_solar_plots() -> plt.Figure:
subfig_season.colorbar(
mesh3,
ax=[ax3, ax6],
label="Daily Irradiation (kWh/m²)",
label="Average Daily Irradiation (kW/m²/day)",
location="right",
pad=0.05,
aspect=40,
Expand Down

0 comments on commit 5b54ac0

Please sign in to comment.