I am trying to plot data over a background image in Python for the purpose of data verification, i.e. to see how close the curve I have generated from my own data fits one from a paper that I have a screenshot of saved as a png.
I have tried the code here using the extent
keyword with imshow
:
Adding a background image to a plot with known corner coordinates and here is my code:
import numpy as np
import matplotlib.pyplot as plt
from scipy.misc import imread
import matplotlib.cbook as cbook
np.random.seed(0)
x = np.random.uniform(0.0,10.0,15)
y = np.random.uniform(0.0,1.25,15)
datafile = cbook.get_sample_data('C:\\Users\\andrew.hills\\Desktop\\Capture.png')
img = imread(datafile)
plt.scatter(x,y,zorder=1)
plt.imshow(img, zorder=0, extent=[0.0, 10.0, 0.00, 1.25])
plt.show()
The problem I am having is that the figure appears distorted which I believe is happening because each pixel is set to 1x1 on the axes but my data range is 0.0-10.0 in the x direction and 0.00-1.25 in the y direction:
How do I change this so the image does not appear distorted?