Matplotlib 使用colorbar来设置色阶条:
colorbar(**kwargs)
colorbar(mappable, **kwargs)
colorbar(mappable, cax=cax, **kwargs)
colorbar(mappable, ax=ax, **kwargs)
下面是一个例子:
import numpy as np
import matplotlib.pyplot as plt
N = 100
x, y = np.mgrid[:100, :100]
Z = np.cos(x*0.05+np.random.rand()) + np.sin(y*0.05+np.random.rand())+2*np.random.rand()-1
Zpos = np.ma.masked_less(Z, 0)
Zneg = np.ma.masked_greater(Z, 0)
fig, (ax1, ax2, ax3) = plt.subplots(figsize=(13, 3), ncols=3)
pos = ax1.imshow(Zpos, cmap='Reds', interpolation='none')
fig.colorbar(pos, ax=ax1)
neg = ax2.imshow(Zneg, cmap='Blues_r', interpolation='none')
fig.colorbar(neg, ax=ax2)
pos_neg_clipped = ax3.imshow(Z, cmap='jet', vmin=-2, vmax=2,interpolation='none')
fig.colorbar(pos_neg_clipped, ax=ax3)
plt.show()
