注意
转到末尾 下载完整示例代码。
交互式调整颜色映射范围#
演示如何使用颜色条交互式调整图像上的颜色映射范围。要使用交互功能,您必须处于缩放模式(放大镜工具栏按钮)或平移模式(四向箭头工具栏按钮),并点击颜色条内部。
缩放时,缩放区域的边界框定义了范数的 vmin 和 vmax。使用鼠标右键缩放将按比例扩展 vmin 和 vmax 到选定区域,就像在轴上进行缩小一样。平移时,范数的 vmin 和 vmax 都根据移动方向进行偏移。“主页/后退/前进”按钮也可以用来返回到之前的状态。

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()
脚本总运行时间: (0 分 2.100 秒)