在上一个问题中, ImageGrid中的colobar标签matplotlib有一个向颜色栏添加标签的解决方案,但是这在当前版本中似乎已被打破。
我尝试过的平台:
以下是上一个问题的代码,以及一些在iPython笔记本中运行的额外代码:
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import AxesGrid
def get_demo_image():
import numpy as np
from matplotlib.cbook import get_sample_data
f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
z = np.load(f)
# z is a numpy array of 15x15
return z, (-3,4,-4,3)
def demo_grid_with_single_cbar(fig):
"""
A grid of 2x2 images with a single colorbar
"""
grid = AxesGrid(fig, 132, # similar to subplot(132)
nrows_ncols = (2, 2),
axes_pad = 0.0,
share_all=True,
label_mode = …Run Code Online (Sandbox Code Playgroud)