python - Matplotlib Pyplot logo/image in Plot -


i'm struggling achieve simple goal in matplotlib... want put small logo or indicator in bottom right of graph, without altering axis or real data being displayed. here code now:

fig = plt.figure() plt.rcparams.update({'font.size': 15})  img = plt.imread('./path/to/image.png') ax1 = fig.add_subplot(111) ax1.yaxis.tick_left() ax1.tick_params(axis='y', colors='black', labelsize=15) ax1.tick_params(axis='x', colors='black', labelsize=15)  plt.grid(b=true, which='major', color='#d3d3d3', linestyle='-')  plt.scatter([1,2,3,4,5],[5,4,3,2,1], alpha=1.0)  plt.autoscale(enable=true, axis=u'both')  fig.savefig('figure.png') 

my output below.

this laying photo on whole graph -- i'd scaled 20% of width & height (if possible) , anchored bottom right. ruins axis, because in output should in 0-100 range on both x & y. ideas solve this, scaling big issue.

edit1: i've tried solution below , linked questions here on so. problem relying on extent variable being passed imshow() doesn't work when introducing new data. example plotting scatter plot coming data frame, 0..1000 , 50..100 using extent won't show label or position off.

edit2: there seems progress getting figure length fig.get_size_inches() , passing variable extent. apparently of matplotlib graph calculations done through inches, may promising lead.

enter image description here

import matplotlib.image image import matplotlib.pyplot plt  im = image.imread('debian-swirl.png') fig, ax = plt.subplots() ax.imshow(im, aspect='auto', extent=(0.4, 0.6, .5, .7), zorder=-1) ax.yaxis.tick_left() ax.tick_params(axis='y', colors='black', labelsize=15) ax.tick_params(axis='x', colors='black', labelsize=15) ax.grid(b=true, which='major', color='#d3d3d3', linestyle='-') ax.scatter([1,2,3,4,5],[5,4,3,2,1], alpha=1.0) plt.show() 

enter image description here

i added png file bottom left. adjust extent parameter set logo position.

similar : scale image in matplotlib without changing axis


Popular posts from this blog