From ced16ffdb281c59e89b0a86932a6711f4cb74b66 Mon Sep 17 00:00:00 2001 From: Tristan Gerrish Date: Thu, 7 Dec 2023 11:14:48 +0000 Subject: [PATCH] fixed bug which meant windroses were rendered incorrectly --- .../ladybugtools_toolkit/plot/utilities.py | 9 +++++---- .../Python/src/ladybugtools_toolkit/wind.py | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/plot/utilities.py b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/plot/utilities.py index 53490a80..879ff452 100644 --- a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/plot/utilities.py +++ b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/plot/utilities.py @@ -611,14 +611,14 @@ def create_triangulation( @bhom_analytics() -def format_polar_plot(ax: plt.Axes) -> plt.Axes: - """Format a polar plot, to svae on having to write this every time!""" +def format_polar_plot(ax: plt.Axes, yticklabels: bool = True) -> plt.Axes: + """Format a polar plot, to save on having to write this every time!""" ax.set_theta_zero_location("N") ax.set_theta_direction(-1) # format plot area ax.spines["polar"].set_visible(False) - ax.grid(True, which="both", ls="--", zorder=0, alpha=0.5) + ax.grid(True, which="both", ls="--", zorder=0, alpha=0.3) ax.yaxis.set_major_locator(plt.MaxNLocator(6)) plt.setp(ax.get_yticklabels(), fontsize="small") ax.set_xticks(np.radians((0, 90, 180, 270)), minor=False) @@ -647,4 +647,5 @@ def format_polar_plot(ax: plt.Axes) -> plt.Axes: minor=True, **{"fontsize": "x-small"}, ) - ax.set_yticklabels([]) + if not yticklabels: + ax.set_yticklabels([]) diff --git a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/wind.py b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/wind.py index a539fa2d..9586980d 100644 --- a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/wind.py +++ b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/wind.py @@ -1808,13 +1808,6 @@ def plot_windrose( remove_calm=True, ) - # set y-axis limits - if not ylim: - ylim = (0, max(binned.sum(axis=1)) + 0.01 if label else 0) - if len(ylim) != 2: - raise ValueError("ylim must be a tuple of length 2.") - ax.set_ylim(ylim) - # set colors if colors is None: if other_data is None: @@ -1846,8 +1839,6 @@ def plot_windrose( ax.set_title(textwrap.fill(f"{self.source}", 75)) - format_polar_plot(ax) - theta_width = np.deg2rad(360 / directions) patches = [] color_list = [] @@ -1891,6 +1882,16 @@ def plot_windrose( title_fontsize="small", ) + # set y-axis limits + if ylim is None: + ylim = (0, max(binned.sum(axis=1))) + if len(ylim) != 2: + raise ValueError("ylim must be a tuple of length 2.") + ax.set_ylim(ylim) + ax.yaxis.set_major_formatter(mticker.PercentFormatter(xmax=1)) + + format_polar_plot(ax, yticklabels=True) + return ax def plot_windhistogram(