Closed
Description
Sorry if this is a duplicate...it seems like this would have come up for somebody else before, but I can't find anything about it.
Bug report
Bug summary
When using AxesGrid and the 'extend' option for filled contours, the last rectangular color levels before the arrow-shaped endpoints are blank. A workaround is to manually create the colorbar via mpl.colorbar.ColorbarBase
.
Code for reproduction
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import AxesGrid
import matplotlib as mpl
levels = np.arange(0., 1.2, 0.15)
# This yields blank values just before the end arrows in the colorbar.
fig = plt.figure()
axgrid = AxesGrid(fig, 111,
nrows_ncols=(1, 1),
ngrids=1,
cbar_mode='single')
ax = axgrid[0]
cs = ax.contourf(np.random.random((10, 20)),
extend='both')
cbar = axgrid.cbar_axes[0].colorbar(cs)
# This problem does not occur when not using AxesGrid.
fig, ax = plt.subplots()
cs = ax.contourf(np.random.random((10, 20)),
extend='both')
cbar = plt.colorbar(cs, ax=ax)
# The problem also doesn't occur if using AxesGrid + manually creating the colorbar.
fig = plt.figure()
axgrid = AxesGrid(fig, 111,
nrows_ncols=(1, 1),
ngrids=1,
cbar_mode='single')
ax = axgrid[0]
cs = ax.contourf(np.random.random((10, 20)),
extend='both', levels=levels)
cmap = mpl.cm.viridis
cb = mpl.colorbar.ColorbarBase(axgrid.cbar_axes[0], cmap=cmap,
boundaries=levels,
orientation='vertical', extend='both')
See the attached images.
Matplotlib version
- Operating system: MacOS + Jupyter Notebook
- Matplotlib version: 2.1.0
- Matplotlib backend (
print(matplotlib.get_backend())
): MacOSX - Python version: 3.6
- Jupyter version (if applicable): 4.3.0
- Other libraries:
Matplotlib installed via conda install -c conda-forge matplotlib