From 77149ba261a6f317cf381ce7d6a02c82fbe4a6af Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 20 Apr 2021 21:11:31 +0200 Subject: [PATCH] Fix axvspan for drawing slices on polar plots. There's already special-casing for polar plots in bar() (using the same `_interpolation_steps = 100`); it seems reasonable to use the same approach for axvspan (e.g. `polar(); axvspan(0, pi/4)`). It seems like making axhspan work (basically drawing full rings) is less easy, but there's an easy enough workaround (`polar(); bar(0, bottom=1, height=1, width=2*pi)`) as the "x" (theta) extent is actually known in that case. --- doc/api/next_api_changes/behavior/20027-AL.rst | 3 +++ lib/matplotlib/axes/_axes.py | 1 + lib/matplotlib/tests/test_polar.py | 6 ++++++ 3 files changed, 10 insertions(+) create mode 100644 doc/api/next_api_changes/behavior/20027-AL.rst diff --git a/doc/api/next_api_changes/behavior/20027-AL.rst b/doc/api/next_api_changes/behavior/20027-AL.rst new file mode 100644 index 000000000000..59e5063a6c1b --- /dev/null +++ b/doc/api/next_api_changes/behavior/20027-AL.rst @@ -0,0 +1,3 @@ +``axvspan`` now plots full wedges in polar plots +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +... rather than triangles. diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index a1edff4a5a83..3d9d649499e4 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -974,6 +974,7 @@ def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs): verts = [(xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)] p = mpatches.Polygon(verts, **kwargs) p.set_transform(self.get_xaxis_transform(which="grid")) + p.get_path()._interpolation_steps = 100 self.add_patch(p) self._request_autoscale_view(scaley=False) return p diff --git a/lib/matplotlib/tests/test_polar.py b/lib/matplotlib/tests/test_polar.py index e3cec7b410e6..1c8f15cc0894 100644 --- a/lib/matplotlib/tests/test_polar.py +++ b/lib/matplotlib/tests/test_polar.py @@ -373,3 +373,9 @@ def test_default_thetalocator(): ticklocs = np.degrees(ax.xaxis.get_majorticklocs()).tolist() assert pytest.approx(90) in ticklocs assert pytest.approx(100) not in ticklocs + + +def test_axvspan(): + ax = plt.subplot(projection="polar") + span = plt.axvspan(0, np.pi/4) + assert span.get_path()._interpolation_steps > 1