Skip to content

Commit

Permalink
fixed bug which meant windroses were rendered incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
tg359 committed Dec 7, 2023
1 parent 9ae87f1 commit ced16ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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([])
19 changes: 10 additions & 9 deletions LadybugTools_Engine/Python/src/ladybugtools_toolkit/wind.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ced16ff

Please sign in to comment.