渐变条形图

渐变条形图

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. np.random.seed(19680801)
  4. def gbar(ax, x, y, width=0.5, bottom=0):
  5. X = [[.6, .6], [.7, .7]]
  6. for left, top in zip(x, y):
  7. right = left + width
  8. ax.imshow(X, interpolation='bicubic', cmap=plt.cm.Blues,
  9. extent=(left, right, bottom, top), alpha=1)
  10. xmin, xmax = xlim = 0, 10
  11. ymin, ymax = ylim = 0, 1
  12. fig, ax = plt.subplots()
  13. ax.set(xlim=xlim, ylim=ylim, autoscale_on=False)
  14. X = [[.6, .6], [.7, .7]]
  15. ax.imshow(X, interpolation='bicubic', cmap=plt.cm.copper,
  16. extent=(xmin, xmax, ymin, ymax), alpha=1)
  17. N = 10
  18. x = np.arange(N) + 0.25
  19. y = np.random.rand(N)
  20. gbar(ax, x, y, width=0.7)
  21. ax.set_aspect('auto')
  22. plt.show()

下载这个示例