import matplotlib.pyplot as plt
import matplotlib.image as image

from matplotlib.offsetbox import OffsetImage, AnnotationBbox

POINTS = {'P1': [589.322, 2950.081],
          'P2': [588.681, 2947.203],
          'P3': [597.041, 2939.515],
          'P4': [602.735, 2941.183]}



def image_in_axes():

    # Create a figure and axes
    fig = plt.figure()
    fig.subplots_adjust(left=0.02, bottom=0.04, right=0.98, top=0.975)

    ax = fig.add_subplot(111)

    # set axes limits
    ax.set_ylim(2910, 2960)
    ax.set_xlim(570, 615)

    # Read in our png file
    im = image.imread('smiley.png')

    # THIS IS THE PROBLEM!!!
    ax.set_aspect('equal')

    for label, coords in POINTS.items():
        x, y = coords

        # Plot our point location
        ax.plot(x, y, 'ko', ms=8)

        imbox = OffsetImage(im, zoom=1)

        ab = AnnotationBbox(imbox, (x, y),
                            xybox=(0., 0.),
                            xycoords='data',
                            box_alignment=(0, 0),
                            boxcoords="offset points",
                            pad=0.,
                            )

        ab.set_zorder(1.5)
        ab.patch.set_visible(False)
        ax.add_artist(ab)


    fig.savefig('image_in_axes.png', dpi=fig.dpi)


if __name__ == '__main__':
    image_in_axes()
    plt.show()

