On 7/15/07, Navid Parvini <[EMAIL PROTECTED]> wrote:

In stead of saving the figure by "pylab.savefig()" command, I want to get
the figure in
array type.

Would you please help me to do that?

Here is an example using agg

import matplotlib
matplotlib.use('Agg')
from pylab import figure, show
import numpy as npy

# make an agg figure
fig = figure()
ax = fig.add_subplot(111)
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
buf = fig.canvas.buffer_rgba(0,0)
l, b, w, h = fig.bbox.get_bounds()
X = npy.fromstring(buf, npy.uint8)
X.shape = h,w,4

# now display the array X as an Axes in a new figure for illustration
fig2 = figure()
ax2 = fig2.add_subplot(111, frameon=False)
ax2.imshow(X)
fig2.savefig('simple.png')
show()

<<attachment: simple.png>>

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to