Here’s a reprex
<code>import urllib # to retrieve the file from the internet
from PIL import Image # to interpret the bytes as an image
import numpy as np # to work with arrays of numbers (the image is an array of pixels)
import matplotlib.pyplot as plt # for general plotting
# The URL for the file
url = r"https://upload.wikimedia.org/wikipedia/en/9/9d/The_Tilled_Field.jpg"
img = np.array(Image.open(urllib.request.urlopen(url)))
# Make a figure and axes
fig, ax = plt.subplots(figsize=(4.5, 6.4))
# Add the image to the axes
ax.imshow(img);
# Say where to put the ticks on the axes
ax.set_xticks(range(0,1300,100), minor=False)
ax.set_xticks(range(0,1300,20), minor=True)
ax.set_yticks(range(0,900,100), minor=False)
ax.set_yticks(range(0,900,20), minor=True)
# Add some gridlines
ax.grid(which='minor', color='grey');
# I want this figure to be inlayed inside the bigger figure
ax.imshow(img, extent=[400,528,200,290]);
</code>
<code>import urllib # to retrieve the file from the internet
from PIL import Image # to interpret the bytes as an image
import numpy as np # to work with arrays of numbers (the image is an array of pixels)
import matplotlib.pyplot as plt # for general plotting
# The URL for the file
url = r"https://upload.wikimedia.org/wikipedia/en/9/9d/The_Tilled_Field.jpg"
img = np.array(Image.open(urllib.request.urlopen(url)))
# Make a figure and axes
fig, ax = plt.subplots(figsize=(4.5, 6.4))
# Add the image to the axes
ax.imshow(img);
# Say where to put the ticks on the axes
ax.set_xticks(range(0,1300,100), minor=False)
ax.set_xticks(range(0,1300,20), minor=True)
ax.set_yticks(range(0,900,100), minor=False)
ax.set_yticks(range(0,900,20), minor=True)
# Add some gridlines
ax.grid(which='minor', color='grey');
# I want this figure to be inlayed inside the bigger figure
ax.imshow(img, extent=[400,528,200,290]);
</code>
import urllib # to retrieve the file from the internet
from PIL import Image # to interpret the bytes as an image
import numpy as np # to work with arrays of numbers (the image is an array of pixels)
import matplotlib.pyplot as plt # for general plotting
# The URL for the file
url = r"https://upload.wikimedia.org/wikipedia/en/9/9d/The_Tilled_Field.jpg"
img = np.array(Image.open(urllib.request.urlopen(url)))
# Make a figure and axes
fig, ax = plt.subplots(figsize=(4.5, 6.4))
# Add the image to the axes
ax.imshow(img);
# Say where to put the ticks on the axes
ax.set_xticks(range(0,1300,100), minor=False)
ax.set_xticks(range(0,1300,20), minor=True)
ax.set_yticks(range(0,900,100), minor=False)
ax.set_yticks(range(0,900,20), minor=True)
# Add some gridlines
ax.grid(which='minor', color='grey');
# I want this figure to be inlayed inside the bigger figure
ax.imshow(img, extent=[400,528,200,290]);
I thought extent would make the second ax.imshow
put the image inside the first, but it doesn’t.
If I remove that line, it does exactly what I expect. But when I use that line, instead of plotting on top of the previous image, in the specified extent, it seems to create a brand new plot.
Does anyone know what I’m doing wrong?