Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ in every released version.
* Fix issue where sometimes the plot sectors showed a straight line instead of a curved one (#137)
* `wrscatter` now converts the wind direction from degrees to radians, so scatter
plots use the same North-up, clockwise convention as the other plots (#99)
* Radial tick labels show percentages when a wind rose uses `normed=True` (#294)

### Version 1.7.0

Expand Down
Binary file modified tests/output/df/test_bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/output/func/test_wrbar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/output/oo/test_windrose_stacked_histogram_normed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/output/test_bar_from_factory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions tests/test_windrose.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,54 @@ def test_theta_labels():
plt.close()


@pytest.mark.parametrize("kind", ["bar", "box", "contour", "contourf"])
@pytest.mark.parametrize("normed, suffix", [(False, ""), (True, "%")])
def test_radial_label_units(kind, normed, suffix):
data = pd.DataFrame({"direction": [0, 90], "speed": [1, 2]})
ax = plot_windrose(data, kind=kind, normed=normed)
try:
expected = (
["10%", "20%", "30%", "40%", "50%"]
if normed
else [
"0.2",
"0.4",
"0.6",
"0.8",
"1.0",
]
)
assert [tick.get_text() for tick in ax.get_yticklabels()] == expected

ax.set_rmax(12.5)
ax.set_radii_angle(angle=90)
expected = [f"{r:.1f}{suffix}" for r in (2.5, 5, 7.5, 10, 12.5)]
assert [tick.get_text() for tick in ax.get_yticklabels()] == expected

ax.clear()
ax.set_rmax(10)
ax.set_radii_angle()
assert [tick.get_text() for tick in ax.get_yticklabels()] == [
"2",
"4",
"6",
"8",
"10",
]
finally:
plt.close(ax.figure)


def test_tex_radial_labels_escape_percent_sign():
ax = WindroseAxes.from_ax()
try:
ax.bar(np.array([0, 90]), np.array([1, 2]), normed=True)
ax.set_radii_angle(usetex=True)
assert ax.get_yticklabels()[-1].get_text() == r"50\%"
finally:
plt.close(ax.figure)


def test_windrose_incorrect_bins_specified():
ax = WindroseAxes.from_ax()
with pytest.raises(ValueError) as exc_info:
Expand Down
9 changes: 8 additions & 1 deletion windrose/windrose.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def clear(self):
self.patches_list = []

self.calm_count = None
self._normed = False

def _colors(self, cmap, n):
"""
Expand All @@ -174,7 +175,11 @@ def set_radii_angle(self, **kwargs):
fmt = "%d"
else:
fmt = "%.1f"
radii_labels = [fmt % r for r in radii]
suffix = ""
if self._normed:
usetex = kwargs.get("usetex", mpl.rcParams["text.usetex"])
suffix = r"\%" if usetex else "%"
radii_labels = [(fmt % r) + suffix for r in radii]
# radii_labels[0] = "" # Removing label 0
self.set_rgrids(
radii=radii[1:],
Expand Down Expand Up @@ -310,6 +315,7 @@ def _init_plot(self, direction, var, **kwargs):
Other Parameters
----------------
normed : boolean, default False
Express the sector frequencies and radial labels as percentages.
blowto : boolean, default False
colors : str or list of str, default None
The colors of the plot.
Expand Down Expand Up @@ -455,6 +461,7 @@ def _init_plot(self, direction, var, **kwargs):
normed,
blowto,
)
self._normed = normed

return bins, nbins, nsector, colors, angles, kwargs

Expand Down