|
From: <jd...@us...> - 2007-07-15 15:33:10
|
Revision: 3532
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3532&view=rev
Author: jdh2358
Date: 2007-07-15 08:33:02 -0700 (Sun, 15 Jul 2007)
Log Message:
-----------
added agg buffer to numpy array example
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/backends/backend_agg.py
trunk/matplotlib/lib/matplotlib/image.py
Added Paths:
-----------
trunk/matplotlib/examples/agg_buffer_to_array.py
Added: trunk/matplotlib/examples/agg_buffer_to_array.py
===================================================================
--- trunk/matplotlib/examples/agg_buffer_to_array.py (rev 0)
+++ trunk/matplotlib/examples/agg_buffer_to_array.py 2007-07-15 15:33:02 UTC (rev 3532)
@@ -0,0 +1,24 @@
+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 rhe pixel buffer and dumpy 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
+fig2 = figure()
+ax2 = fig2.add_subplot(111, frameon=False)
+ax2.imshow(X)
+fig2.savefig('simple.png')
+show()
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_agg.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-07-15 05:08:57 UTC (rev 3531)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-07-15 15:33:02 UTC (rev 3532)
@@ -382,8 +382,8 @@
"""
if __debug__: verbose.report('FigureCanvasAgg.draw', 'debug-annoying')
- renderer = self.get_renderer()
- self.figure.draw(renderer)
+ self.renderer = self.get_renderer()
+ self.figure.draw(self.renderer)
def get_renderer(self):
l,b,w,h = self.figure.bbox.get_bounds()
Modified: trunk/matplotlib/lib/matplotlib/image.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/image.py 2007-07-15 05:08:57 UTC (rev 3531)
+++ trunk/matplotlib/lib/matplotlib/image.py 2007-07-15 15:33:02 UTC (rev 3532)
@@ -264,7 +264,9 @@
if self._extent is not None:
return self._extent
else:
- numrows, numcols = self.get_size()
+ sz = self.get_size()
+ #print 'sz', sz
+ numrows, numcols = sz
if self.origin == 'upper':
return (-0.5, numcols-0.5, numrows-0.5, -0.5)
else:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|