Python scatter plot over background image for data verification -


i trying plot data on background image in python purpose of data verification, i.e. see how close curve have generated own data fits 1 paper have screenshot of saved png.

i have tried code here using extent keyword imshow: adding background image plot known corner coordinates , here code:

import numpy np import matplotlib.pyplot plt scipy.misc import imread import matplotlib.cbook 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 having figure appears distorted believe happening because each pixel set 1x1 on axes data range 0.0-10.0 in x direction , 0.00-1.25 in y direction:

enter image description here

how change image not appear distorted?

the problem indeed image new data range through extent argument , aspect ratio of image, "equal" default therefore lead distorted image.

what need calculate new aspect ratio takes new data range account.

new_aspect = #pixels along y /

import numpy np import matplotlib.pyplot plt  np.random.seed(0) x = np.random.uniform(0.0,10.0,15) y = np.random.uniform(0.0,1.25,15) plt.scatter(x,y,zorder=1)  img = plt.imread("house.png")  ext = [0.0, 10.0, 0.00, 1.25] plt.imshow(img, zorder=0, extent=ext)  aspect=img.shape[0]/float(img.shape[1])*((ext[1]-ext[0])/(ext[3]-ext[2])) plt.gca().set_aspect(aspect)  plt.show() 

enter image description here


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -