diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index e812550c46fd..226dd408c874 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -790,8 +790,6 @@ def add_lines(self, *args, **kwargs): xy[[2, 3], 1] += fac # back to axes units... xy = self.ax.transAxes.inverted().transform(inches.transform(xy)) - if self.orientation == 'horizontal': - xy = xy.T col.set_clip_path(mpath.Path(xy, closed=True), self.ax.transAxes) self.ax.add_collection(col) diff --git a/lib/matplotlib/tests/baseline_images/test_colorbar/contour_colorbar.png b/lib/matplotlib/tests/baseline_images/test_colorbar/contour_colorbar.png new file mode 100644 index 000000000000..bf084c30ddad Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_colorbar/contour_colorbar.png differ diff --git a/lib/matplotlib/tests/test_colorbar.py b/lib/matplotlib/tests/test_colorbar.py index b85726d9146b..1b14178c991d 100644 --- a/lib/matplotlib/tests/test_colorbar.py +++ b/lib/matplotlib/tests/test_colorbar.py @@ -185,6 +185,17 @@ def test_colorbar_positioning(use_gridspec): anchor=(0.8, 0.5), shrink=0.6, use_gridspec=use_gridspec) +@image_comparison(['contour_colorbar.png'], remove_text=True) +def test_contour_colorbar(): + fig, ax = plt.subplots(figsize=(4, 2)) + data = np.arange(1200).reshape(30, 40) - 500 + levels = np.array([0, 200, 400, 600, 800, 1000, 1200]) - 500 + + CS = ax.contour(data, levels=levels, extend='both') + fig.colorbar(CS, orientation='horizontal', extend='both') + fig.colorbar(CS, orientation='vertical') + + @image_comparison(['cbar_with_subplots_adjust.png'], remove_text=True, savefig_kwarg={'dpi': 40}) def test_gridspec_make_colorbar():