diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index c4967025e136..78cfe19df1ed 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3186,6 +3186,10 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0, marker_y = heads baseline_x = [np.min(locs), np.max(locs)] baseline_y = [bottom, bottom] + if self.name == "polar": + # The baseline must be interpolated to follow the curvature + baseline_x = np.linspace(*baseline_x, 200) + baseline_y = np.linspace(*baseline_y, 200) markerline, = self.plot(marker_x, marker_y, color=markercolor, linestyle=markerstyle, diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 237a0a044253..c79a62021fa5 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4617,6 +4617,23 @@ def test_stem_orientation(): orientation='horizontal') +def test_stem_polar_baseline(): + """Test that the baseline is sampled so that it will follow the radius.""" + fig = plt.figure() + ax = fig.add_subplot(projection='polar') + x = np.linspace(1.57, 3.14, 10) + y = np.linspace(0, 1, 10) + bottom = 0.5 + container = ax.stem(x, y, bottom=bottom) + baseline_x, baseline_y = container.baseline.get_data() + # The number of baseline points N_BASELINE_POINTS is an implementation detail. + # Nevertheless, it's simpler and clearer to test with this detail rather than + # to generically test "sufficiently high sampled". + N_BASELINE_POINTS = 200 + assert_allclose(baseline_x, np.linspace(x.min(), x.max(), N_BASELINE_POINTS)) + assert_allclose(baseline_y, np.full(N_BASELINE_POINTS, bottom) + + @image_comparison(['hist_stacked_stepfilled_alpha']) def test_hist_stacked_stepfilled_alpha(): # make some data