Skip to content

Commit 4c04b19

Browse files
committed
np.fromstring -> np.frombuffer.
Use of fromstring on binary data is deprecated since numpy 1.14.
1 parent 747c2a7 commit 4c04b19

File tree

5 files changed

+7
-12
lines changed

5 files changed

+7
-12
lines changed

examples/images_contours_and_fields/image_demo.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
The most common way to plot images in Matplotlib is with
99
:meth:`~.axes.Axes.imshow`. The following examples demonstrate much of the
1010
functionality of imshow and the many images you can create.
11-
1211
"""
1312

1413
import numpy as np
@@ -54,7 +53,7 @@
5453

5554
with cbook.get_sample_data('ct.raw.gz', asfileobj=True) as datafile:
5655
s = datafile.read()
57-
A = np.fromstring(s, np.uint16).astype(float).reshape((w, h))
56+
A = np.frombuffer(s, np.uint16).astype(float).reshape((w, h))
5857
A /= A.max()
5958

6059
fig, ax = plt.subplots()

examples/misc/agg_buffer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
s, (width, height) = agg.print_to_buffer()
2222

2323
# Convert to a NumPy array.
24-
X = np.fromstring(s, np.uint8).reshape((height, width, 4))
24+
X = np.frombuffer(s, np.uint8).reshape((height, width, 4))
2525

2626
# Pass off to PIL.
2727
from PIL import Image

examples/specialty_plots/mri_demo.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@
33
MRI
44
===
55
6-
76
This example illustrates how to read an image (of an MRI) into a NumPy
87
array, and display it in greyscale using `imshow`.
9-
108
"""
119

1210
import matplotlib.pyplot as plt
1311
import matplotlib.cbook as cbook
14-
import matplotlib.cm as cm
1512
import numpy as np
1613

1714

18-
# Data are 256x256 16 bit integers
15+
# Data are 256x256 16 bit integers.
1916
with cbook.get_sample_data('s1045.ima.gz') as dfile:
20-
im = np.fromstring(dfile.read(), np.uint16).reshape((256, 256))
17+
im = np.frombuffer(dfile.read(), np.uint16).reshape((256, 256))
2118

2219
fig, ax = plt.subplots(num="MRI_demo")
23-
ax.imshow(im, cmap=cm.gray)
20+
ax.imshow(im, cmap="gray")
2421
ax.axis('off')
2522

2623
plt.show()

examples/specialty_plots/mri_with_eeg.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
histogram and some EEG traces.
88
"""
99

10-
1110
import numpy as np
1211
import matplotlib.pyplot as plt
1312
import matplotlib.cbook as cbook
@@ -20,7 +19,7 @@
2019

2120
# Load the MRI data (256x256 16 bit integers)
2221
with cbook.get_sample_data('s1045.ima.gz') as dfile:
23-
im = np.fromstring(dfile.read(), np.uint16).reshape((256, 256))
22+
im = np.frombuffer(dfile.read(), np.uint16).reshape((256, 256))
2423

2524
# Plot the MRI image
2625
ax0 = fig.add_subplot(2, 2, 1)

examples/user_interfaces/canvasagg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
s, (width, height) = canvas.print_to_buffer()
4343

4444
# Option 2a: Convert to a NumPy array.
45-
X = np.fromstring(s, np.uint8).reshape((height, width, 4))
45+
X = np.frombuffer(s, np.uint8).reshape((height, width, 4))
4646

4747
# Option 2b: Pass off to PIL.
4848
from PIL import Image

0 commit comments

Comments
 (0)