8000 np.fromstring -> np.frombuffer. by anntzer · Pull Request #12466 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

np.fromstring -> np.frombuffer. #12466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/images_contours_and_fields/image_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
The most common way to plot images in Matplotlib is with
:meth:`~.axes.Axes.imshow`. The following examples demonstrate much of the
functionality of imshow and the many images you can create.

"""

import numpy as np
Expand Down Expand Up @@ -54,7 +53,7 @@

with cbook.get_sample_data('ct.raw.gz', asfileobj=True) as datafile:
s = datafile.read()
A = np.fromstring(s, np.uint16).astype(float).reshape((w, h))
A = np.frombuffer(s, np.uint16).astype(float).reshape((w, h))
A /= A.max()

fig, ax = plt.subplots()
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/agg_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
s, (width, height) = agg.print_to_buffer()

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

# Pass off to PIL.
from PIL import Image
Expand Down
9 changes: 3 additions & 6 deletions examples/specialty_plots/mri_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@
MRI
===


This example illustrates how to read an image (of an MRI) into a NumPy
array, and display it in greyscale using `imshow`.

"""

import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
import matplotlib.cm as cm
import numpy as np


# Data are 256x256 16 bit integers
# Data are 256x256 16 bit integers.
with cbook.get_sample_data('s1045.ima.gz') as dfile:
im = np.fromstring(dfile.read(), np.uint16).reshape((256, 256))
im = np.frombuffer(dfile.read(), np.uint16).reshape((256, 256))

fig, ax = plt.subplots(num="MRI_demo")
ax.imshow(im, cmap=cm.gray)
ax.imshow(im, cmap="gray")
ax.axis('off')

plt.show()
3 changes: 1 addition & 2 deletions examples/specialty_plots/mri_with_eeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
histogram and some EEG traces.
"""


import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
Expand All @@ -20,7 +19,7 @@

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

# Plot the MRI image
ax0 = fig.add_subplot(2, 2, 1)
Expand Down
2 changes: 1 addition & 1 deletion examples/user_interfaces/canvasagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
s, (width, height) = canvas.print_to_buffer()

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

# Option 2b: Pass off to PIL.
from PIL import Image
Expand Down
0