As in the MATLAB example you contacted, you must specify the desired image length when invoking imshow .
By default, matplotlib and MATLAB place the top left corner of the image at the origin, go down and to the right from there, and set each pixel as a 1x1 square in the coordinate space. This is what makes your image.
You can control this with the extent parameter, which takes the form of a list [left, right, bottom, top] .
Inability to use is as follows:
import matplotlib.pyplot as plt img = plt.imread("airlines.jpg") fig, ax = plt.subplots() ax.imshow(img)

You can see that we have 1600 x 1200 from Samuel L. Jackson, quite frankly, rather annoyed by the snake aboard his airline flight.
But if we want to build a line in size from 0 to 300 in both dimensions above this, we can do just that:
fig, ax = plt.subplots() x = range(300) ax.imshow(img, extent=[0, 400, 0, 300]) ax.plot(x, x, '--', linewidth=5, color='firebrick')

I don't know if this line will help Mr. Jackson with his snake problem. At least this will not complicate the situation.