Agg缓冲区转换数组

将渲染图形转换为其图像(NumPy数组)表示形式。

Agg缓冲区转换数组示例

Agg缓冲区转换数组示例2

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. # make an agg figure
  4. fig, ax = plt.subplots()
  5. ax.plot([1, 2, 3])
  6. ax.set_title('a simple figure')
  7. fig.canvas.draw()
  8. # grab the pixel buffer and dump it into a numpy array
  9. X = np.array(fig.canvas.renderer._renderer)
  10. # now display the array X as an Axes in a new figure
  11. fig2 = plt.figure()
  12. ax2 = fig2.add_subplot(111, frameon=False)
  13. ax2.imshow(X)
  14. plt.show()

下载这个示例