Skip to content

Commit 77149ba

Browse files
committed
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.
1 parent 5c8cf78 commit 77149ba

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``axvspan`` now plots full wedges in polar plots
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... rather than triangles.

lib/matplotlib/axes/_axes.py

+1
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs):
974974
verts = [(xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)]
975975
p = mpatches.Polygon(verts, **kwargs)
976976
p.set_transform(self.get_xaxis_transform(which="grid"))
977+
p.get_path()._interpolation_steps = 100
977978
self.add_patch(p)
978979
self._request_autoscale_view(scaley=False)
979980
return p

lib/matplotlib/tests/test_polar.py

+6
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,9 @@ def test_default_thetalocator():
373373
ticklocs = np.degrees(ax.xaxis.get_majorticklocs()).tolist()
374374
assert pytest.approx(90) in ticklocs
375375
assert pytest.approx(100) not in ticklocs
376+
377+
378+
def test_axvspan():
379+
ax = plt.subplot(projection="polar")
380+
span = plt.axvspan(0, np.pi/4)
381+
assert span.get_path()._interpolation_steps > 1

0 commit comments

Comments
 (0)