Skip to content

Commit fa0a66a

Browse files
weber-sSamuelocefpaf
authored
fix some of my messy previous change that broke theta_labels... (#146)
* fix some of my messy previous change that broke theta_labels... * fix to support python2 * rebase and adapt to the new tests Co-authored-by: Samuel <[email protected]> Co-authored-by: Filipe Fernandes <[email protected]>
1 parent f4924e6 commit fa0a66a

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

tests/test_windrose.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import matplotlib
2+
import matplotlib.pyplot as plt
23
import numpy as np
34
import pandas as pd
45
from numpy.testing import assert_allclose
56
from pandas.testing import assert_frame_equal
67

7-
from windrose import clean, clean_df, plot_windrose
8+
from windrose import DEFAULT_THETA_LABELS, WindroseAxes, clean, clean_df, plot_windrose
89

910
matplotlib.use("Agg") # noqa
1011
# Create wind speed and direction variables
@@ -52,3 +53,17 @@ def test_windrose_clean_df():
5253
}
5354
)
5455
assert_frame_equal(actual_df, expected_df)
56+
57+
58+
def test_theta_labels():
59+
# Ensure default theta_labels are correct
60+
ax = WindroseAxes.from_ax()
61+
theta_labels = [t.get_text() for t in ax.get_xticklabels()]
62+
assert theta_labels == DEFAULT_THETA_LABELS
63+
plt.close()
64+
65+
# Ensure theta_labels are changed when specified
66+
ax = WindroseAxes.from_ax(theta_labels=list("abcdefgh"))
67+
theta_labels = [t.get_text() for t in ax.get_xticklabels()]
68+
assert theta_labels == ["a", "b", "c", "d", "e", "f", "g", "h"]
69+
plt.close()

windrose/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from matplotlib.projections import register_projection
44

55
from .windrose import D_KIND_PLOT # noqa
6+
from .windrose import DEFAULT_THETA_LABELS # noqa
67
from .windrose import DPI_DEFAULT # noqa
78
from .windrose import FIGSIZE_DEFAULT # noqa
89
from .windrose import WindAxes # noqa

windrose/windrose.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
DPI_DEFAULT = 80
1818
CALM_CIRCLE_COLOR = "red"
1919
CALM_CIRCLE_ALPHA = 0.4
20+
DEFAULT_THETA_LABELS = ["E", "N-E", "N", "N-W", "W", "S-W", "S", "S-E"]
2021

2122

2223
class WindAxesFactory:
@@ -70,24 +71,26 @@ class WindroseAxes(PolarAxes):
7071
def __init__(self, *args, **kwargs):
7172
"""
7273
See Axes base class for args and kwargs documentation
74+
75+
Other kwargs are:
76+
77+
theta_labels : default ["E", "N-E", "N", "N-W", "W", "S-W", "S", "S-E"]
78+
Labels for theta coordinate
7379
"""
7480

7581
# Uncomment to have the possibility to change the resolution directly
7682
# when the instance is created
7783
# self.RESOLUTION = kwargs.pop('resolution', 100)
7884
self.rmax = kwargs.pop("rmax", None)
79-
self.theta_labels = kwargs.pop("theta_labels", None)
80-
if self.theta_labels is None:
81-
self.theta_labels = ["E", "N-E", "N", "N-W", "W", "S-W", "S", "S-E"]
85+
self.theta_labels = kwargs.pop("theta_labels", DEFAULT_THETA_LABELS)
86+
8287
PolarAxes.__init__(self, *args, **kwargs)
8388
self.set_aspect("equal", adjustable="box", anchor="C")
8489
self.radii_angle = 67.5
8590
self.clear()
8691

8792
@staticmethod
88-
def from_ax(
89-
ax=None, fig=None, rmax=None, theta_labels=None, rect=None, *args, **kwargs
90-
):
93+
def from_ax(ax=None, fig=None, rmax=None, rect=None, *args, **kwargs):
9194
"""
9295
Return a WindroseAxes object for the figure `fig`.
9396
"""
@@ -101,9 +104,7 @@ def from_ax(
101104
)
102105
if rect is None:
103106
rect = [0.1, 0.1, 0.8, 0.8]
104-
ax = WindroseAxes(
105-
fig, rect, rmax=rmax, theta_labels=theta_labels, *args, **kwargs
106-
)
107+
ax = WindroseAxes(fig, rect, rmax=rmax, *args, **kwargs)
107108
fig.add_axes(ax)
108109
return ax
109110
else:

0 commit comments

Comments
 (0)