简单的 RGB

简单的RGB示例

  1. import matplotlib.pyplot as plt
  2. from mpl_toolkits.axes_grid1.axes_rgb import RGBAxes
  3. def get_demo_image():
  4. import numpy as np
  5. from matplotlib.cbook import get_sample_data
  6. f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
  7. z = np.load(f)
  8. # z is a numpy array of 15x15
  9. return z, (-3, 4, -4, 3)
  10. def get_rgb():
  11. Z, extent = get_demo_image()
  12. Z[Z < 0] = 0.
  13. Z = Z / Z.max()
  14. R = Z[:13, :13]
  15. G = Z[2:, 2:]
  16. B = Z[:13, 2:]
  17. return R, G, B
  18. fig = plt.figure(1)
  19. ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8])
  20. r, g, b = get_rgb()
  21. kwargs = dict(origin="lower", interpolation="nearest")
  22. ax.imshow_rgb(r, g, b, **kwargs)
  23. ax.RGB.set_xlim(0., 9.5)
  24. ax.RGB.set_ylim(0.9, 10.6)
  25. plt.show()

下载这个示例