Skip to content

Commit 719c6b7

Browse files
authored
Merge pull request matplotlib#22216 from pharshalp/cax_grid_off
turn off the grid after creating colorbar axes
2 parents 7388222 + 902922a commit 719c6b7

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/matplotlib/figure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,7 @@ def colorbar(
11471147
cax, kwargs = cbar.make_axes_gridspec(ax, **kwargs)
11481148
else:
11491149
cax, kwargs = cbar.make_axes(ax, **kwargs)
1150+
cax.grid(visible=False, which='both', axis='both')
11501151
else:
11511152
userax = True
11521153

lib/matplotlib/tests/test_colorbar.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,3 +938,15 @@ def test_boundaries():
938938
fig, ax = plt.subplots(figsize=(2, 2))
939939
pc = ax.pcolormesh(np.random.randn(10, 10), cmap='RdBu_r')
940940
cb = fig.colorbar(pc, ax=ax, boundaries=np.linspace(-3, 3, 7))
941+
942+
943+
def test_colorbar_no_warning_rcparams_grid_true():
944+
# github issue #21723 - If mpl style has 'axes.grid' = True,
945+
# fig.colorbar raises a warning about Auto-removal of grids
946+
# by pcolor() and pcolormesh(). This is fixed by PR #22216.
947+
plt.rcParams['axes.grid'] = True
948+
fig, ax = plt.subplots()
949+
ax.grid(False)
950+
im = ax.pcolormesh([0, 1], [0, 1], [[1]])
951+
# make sure that no warning is raised by fig.colorbar
952+
fig.colorbar(im)

0 commit comments

Comments
 (0)