python - Insert image on current plot without deformation -


in matplotlib, appropriate way plot image native aspect ratio, , optionally native size, inside existing axes @ specific data location?

for instance:

from matplotlib.pyplot import plot matplotlib.image import imread matplotlib.cbook import get_sample_data  plot([50,60],[1000,2000]) im = imread(get_sample_data("grace_hopper.png", asfileobj=false))  

now want plot im instance centered @ coordinates (57,1200) scaling or max height , without deformation.

i imagine mix between matplotlib.offsetbox.anchoredoffsetbox , matplotlib.offsetbox.offsetimage should trick, i'm not familiar these classes.

as expected, solution in matplotlib.offsetbox module:

from matplotlib.pyplot import plot, gca, show matplotlib.image import imread matplotlib.cbook import get_sample_data matplotlib.offsetbox import offsetimage, annotationbbox  plot([50,60],[1000,2000]) im = imread(get_sample_data("grace_hopper.png", asfileobj=false))     oi = offsetimage(im, zoom=0.1) ab = annotationbbox(oi, (57, 1200), xycoords='data', frameon=false) gca().add_artist(ab) show() 

here result: well scaled , positioned image inside current plot

in fact, annotationbbox needed , alot more numerous options.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -