Skip to content

Commit 75ba03d

Browse files
committed
Use frombuffer and copy instead, since it's Python 3.x compatible.
1 parent 0005ab4 commit 75ba03d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

examples/pylab_examples/agg_buffer_to_array.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
# grab the pixel buffer and dump it into a numpy array
1313
buf = fig.canvas.buffer_rgba()
1414
l, b, w, h = fig.bbox.bounds
15-
X = np.fromstring(buf, np.uint8)
15+
# The array needs to be copied, because the underlying buffer
16+
# may be reallocated when the window is resized.
17+
X = np.frombuffer(buf, np.uint8).copy()
1618
X.shape = h,w,4
1719

1820
# now display the array X as an Axes in a new figure

0 commit comments

Comments
 (0)