diff --git a/CHANGELOG.md b/CHANGELOG.md index 7392ede..ee63b35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ in every released version. ## What's Changed * 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) ### Version 1.7.0 diff --git a/tests/output/df/test_scatter.png b/tests/output/df/test_scatter.png index de1e31a..c97c341 100644 Binary files a/tests/output/df/test_scatter.png and b/tests/output/df/test_scatter.png differ diff --git a/tests/output/df/test_windrose_np_plot_and_pd_plot.png b/tests/output/df/test_windrose_np_plot_and_pd_plot.png index de1e31a..c97c341 100644 Binary files a/tests/output/df/test_windrose_np_plot_and_pd_plot.png and b/tests/output/df/test_windrose_np_plot_and_pd_plot.png differ diff --git a/tests/output/func/test_wrscatter.png b/tests/output/func/test_wrscatter.png index d631609..754b72c 100644 Binary files a/tests/output/func/test_wrscatter.png and b/tests/output/func/test_wrscatter.png differ diff --git a/tests/test_windrose_np_mpl_func.py b/tests/test_windrose_np_mpl_func.py index ee05367..21e09ad 100644 --- a/tests/test_windrose_np_mpl_func.py +++ b/tests/test_windrose_np_mpl_func.py @@ -23,6 +23,19 @@ def test_wrscatter(): return ax.figure +def test_wrscatter_direction_convention(): + # 0 degrees is North (up) and angles increase clockwise, as for the + # bar/box/contour plots: theta = radians(90 - direction). See gh-99. + compass = np.array([0.0, 45.0, 90.0, 180.0, 270.0]) + ax = wrscatter(compass, np.full_like(compass, 10.0)) + theta = ax.collections[0].get_offsets()[:, 0] + two_pi = 2 * np.pi + np.testing.assert_allclose( + np.mod(theta, two_pi), + np.mod(np.radians(90.0 - compass), two_pi), + ) + + @pytest.mark.mpl_image_compare(baseline_dir="output/func", tolerance=5) def test_wrbar(): ax = wrbar(wd, ws, normed=True, opening=0.8, edgecolor="white") diff --git a/windrose/windrose.py b/windrose/windrose.py index 83f4763..f3634be 100644 --- a/windrose/windrose.py +++ b/windrose/windrose.py @@ -957,7 +957,7 @@ def wrscatter( Draw scatter plot """ ax = WindroseAxes.from_ax(ax, rmax=rmax, figsize=figsize) - direction = -np.array(direction) + np.radians(90) + direction = np.radians(90.0 - np.asarray(direction, dtype=float)) ax.scatter(direction, var, *args, **kwargs) return ax