颜色映射规格化

演示使用规范以非线性方式将颜色映射映射到数据上。

颜色映射规格化示例

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import matplotlib.colors as colors
  4. '''
  5. Lognorm: Instead of pcolor log10(Z1) you can have colorbars that have
  6. the exponential labels using a norm.
  7. '''
  8. N = 100
  9. X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)]
  10. # A low hump with a spike coming out of the top right. Needs to have
  11. # z/colour axis on a log scale so we see both hump and spike. linear
  12. # scale only shows the spike.
  13. Z = np.exp(-X**2 - Y**2)
  14. fig, ax = plt.subplots(2, 1)
  15. pcm = ax[0].pcolor(X, Y, Z,
  16. norm=colors.LogNorm(vmin=Z.min(), vmax=Z.max()),
  17. cmap='PuBu_r')
  18. fig.colorbar(pcm, ax=ax[0], extend='max')
  19. pcm = ax[1].pcolor(X, Y, Z, cmap='PuBu_r')
  20. fig.colorbar(pcm, ax=ax[1], extend='max')
  21. plt.show()

下载这个示例