Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a6f9d82

Browse files
greglucasmeeseeksmachine
authored andcommitted
Backport PR #21686: FIX: colorbar for horizontal contours
1 parent 2c69dbb commit a6f9d82

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

lib/matplotlib/colorbar.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,6 @@ def add_lines(self, *args, **kwargs):
783783
xy[[2, 3], 1] += fac
784784
# back to axes units...
785785
xy = self.ax.transAxes.inverted().transform(inches.transform(xy))
786-
if self.orientation == 'horizontal':
787-
xy = xy.T
788786
col.set_clip_path(mpath.Path(xy, closed=True),
789787
self.ax.transAxes)
790788
self.ax.add_collection(col)
5.05 KB
Loading

lib/matplotlib/tests/test_colorbar.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ def test_colorbar_positioning(use_gridspec):
185185
anchor=(0.8, 0.5), shrink=0.6, use_gridspec=use_gridspec)
186186

187187

188+
@image_comparison(['contour_colorbar.png'], remove_text=True)
189+
def test_contour_colorbar():
190+
fig, ax = plt.subplots(figsize=(4, 2))
191+
data = np.arange(1200).reshape(30, 40) - 500
192+
levels = np.array([0, 200, 400, 600, 800, 1000, 1200]) - 500
193+
194+
CS = ax.contour(data, levels=levels, extend='both')
195+
fig.colorbar(CS, orientation='horizontal', extend='both')
196+
fig.colorbar(CS, orientation='vertical')
197+
198+
188199
@image_comparison(['cbar_with_subplots_adjust.png'], remove_text=True,
189200
savefig_kwarg={'dpi': 40})
190201
def test_gridspec_make_colorbar():

0 commit comments

Comments
 (0)