matplotlib

Previous topic

pylab_examples example code: accented_text.py

Next topic

pylab_examples example code: alignment_test.py

This Page

pylab_examples example code: agg_buffer_to_array.pyΒΆ

(Source code)

../../_images/agg_buffer_to_array_00.png

(png)

../../_images/agg_buffer_to_array_01.png

(png)

import matplotlib.pyplot as plt
import numpy as np

# make an agg figure
fig, ax = plt.subplots()
ax.plot([1, 2, 3])
ax.set_title('a simple figure')
fig.canvas.draw()

# grab the pixel buffer and dump it into a numpy array
X = np.array(fig.canvas.renderer._renderer)

# now display the array X as an Axes in a new figure
fig2 = plt.figure()
ax2 = fig2.add_subplot(111, frameon=False)
ax2.imshow(X)
plt.show()

Keywords: python, matplotlib, pylab, example, codex (see Search examples)