Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 39e18ce

Browse files
committed
Merge pull request matplotlib#1437 from mdboom/agg_buffer_to_array_fix
agg_buffer_to_array.py crashes
2 parents 1656ebc + 98dc022 commit 39e18ce

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

examples/pylab_examples/agg_buffer_to_array.py

Lines changed: 3 additions & 1 deletion
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.frombuffer(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)