python - Adding a background image to a plot with known corner coordinates -
say plotting set of points image background. i've used lena image in example:
import numpy np import matplotlib.pyplot plt scipy.misc import imread np.random.seed(0) x = np.random.uniform(0.0,10.0,15) y = np.random.uniform(0.0,10.0,15) img = imread("lena.jpg") plt.scatter(x,y,zorder=1) plt.imshow(img,zorder=0) plt.show() this gives me
.
my question is: how can specify corner coordinates of image in plot? let's i'd bottom-left corner @ x, y = 0.5, 1.0 , top-right corner @ x, y = 8.0, 7.0.
use extent keyword of imshow. order of argument [left, right, bottom, top]
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,10.0,15) datafile = cbook.get_sample_data('lena.jpg') img = imread(datafile) plt.scatter(x,y,zorder=1) plt.imshow(img, zorder=0, extent=[0.5, 8.0, 1.0, 7.0]) plt.show()
Comments
Post a Comment