交互式调整色图范围#

演示如何使用颜色条来交互式地调整图像上颜色映射的范围。要使用交互功能,您必须在缩放模式(放大镜工具栏按钮)或平移模式(四向箭头工具栏按钮)中,并在颜色条内点击。

当缩放时,缩放区域的边界框定义了新的 vmin 和 vmax 的范数。使用鼠标右键缩放将按比例扩展 vmin 和 vmax 到所选区域,就像在轴上缩小时一样。当平移时,范数的 vmin 和 vmax 都根据移动方向进行偏移。Home/Back/Forward 按钮也可以用来返回到之前的状态。

Pan on the colorbar to shift the color mapping Zoom on the colorbar to scale the color mapping
import matplotlib.pyplot as plt
import numpy as np

t = np.linspace(0, 2 * np.pi, 1024)
data2d = np.sin(t)[:, np.newaxis] * np.cos(t)[np.newaxis, :]

fig, ax = plt.subplots()
im = ax.imshow(data2d)
ax.set_title('Pan on the colorbar to shift the color mapping\n'
             'Zoom on the colorbar to scale the color mapping')

fig.colorbar(im, ax=ax, label='Interactive colorbar')

plt.show()

由 Sphinx-Gallery 生成的图库