Moving an image to matplotlib#
import matplotlib.pyplot as plt
# Prompt user for image name
image_name = input('Enter image name (with extension): ')
#base image: "spiderPete.jpg"
# Read the image using matplotlib
image = plt.imread(image_name)
# Display the image
plt.figure()
plt.imshow(image)
plt.title('Spider Pete')
plt.xlabel('It is a spider') # Appropriate label
plt.ylabel('It is Pete') # Appropriate label if needed
# Show the plot
plt.show()
---------------------------------------------------------------------------
StdinNotImplementedError Traceback (most recent call last)
Cell In[1], line 4
1 import matplotlib.pyplot as plt
3 # Prompt user for image name
----> 4 image_name = input('Enter image name (with extension): ')
5 #base image: "spiderPete.jpg"
6 # Read the image using matplotlib
7 image = plt.imread(image_name)
File ~/.local/lib/python3.12/site-packages/ipykernel/kernelbase.py:1281, in Kernel.raw_input(self, prompt)
1279 if not self._allow_stdin:
1280 msg = "raw_input was called, but this frontend does not support input requests."
-> 1281 raise StdinNotImplementedError(msg)
1282 return self._input_request(
1283 str(prompt),
1284 self._parent_ident["shell"],
1285 self.get_parent("shell"),
1286 password=False,
1287 )
StdinNotImplementedError: raw_input was called, but this frontend does not support input requests.
Modifying images in Matplotlib
import matplotlib.pyplot as plt
import numpy as np
image1 = plt.imread('spiderPete.jpg')
image2 = plt.imread('spiderPete.jpg')
x_points = np.random.randint(0, image1.shape[1], 10) # x-coordinates
y_points = np.random.randint(0, image1.shape[0], 10) # y-coordinates
fig, axs = plt.subplots(1, 2, figsize=(8, 5))
axs[0].imshow(image1)
axs[1].imshow(image2)
axs[0].scatter(x_points, y_points, c='red') # red points
axs[1].scatter(x_points, y_points, c='yellow', marker = '^') # yellow Triangles
axs[0].set_title('Pete with red points')
axs[1].set_title('Pete with yellow triangles')
axs[0].set_xlabel('Spider')
axs[1].set_xlabel('Spider')
axs[0].set_ylabel("It's Spider Pete")
axs[1].set_ylabel("It's Spider Pete")
#plt.tight_layout()
plt.savefig("spiderPetePlot.png")
plt.show()
<Figure size 640x480 with 0 Axes>