why unnable to do annotation adjacent to legend?
Question: I am trying to add text to a location that is adjacent to the legend. Here is
what I have tried:

    
    
    import matplotlib.pyplot as plt
    x = y = [1,2,3,4,5]
    fig, ax = plt.subplots()
    ax.plot(x,y)
    leg = ax.legend(['line 1'], loc=6, frameon=False)
    plt.draw()
    p = leg.get_window_extent()
    ax.annotate('Annotation Text', (p.p0[0], p.p1[1]), (p.p0[0], p.p1[1]), 
            xycoords='figure pixels', zorder=9)
    plt.show()
    

This is exactly the script contained in the stackoverflow question at [Get
Matplotlib legend location?](http://stackoverflow.com/questions/28711376/get-
matplotlib-legend-location). When I run the exact same script I produce
different results. When I run this script the string "Annotation Text" appears
at the bottom left of the figure.

For the record, the value of p when I run this script is `Bbox(x0=0.0, y0=0.0,
x1=1.0, y1=1.0)`.

How can I obtain the coordinates of the Legend, preferably in terms of axes
coordinates ie. ax.transAxes ?

I am using matplotlib 1.5.0 and python 2.7


Answer: You can use `inverse_transformed` to convert figure pixels to axes fraction:

    
    
    import matplotlib.pyplot as plt
    
    x = y = [1,2,3,4,5]
    fig, ax = plt.subplots()
    ax.plot(x,y)
    
    leg = ax.legend(['line 1'], loc=6, frameon=False)
    
    fig.canvas.draw()
    
    p = leg.get_window_extent().inverse_transformed(ax.transAxes)
    
    ax.annotate('Annotation Text', (p.p0[0], p.p1[1]), xycoords='axes fraction')
    

This will produce plot like this:

[![enter image description
here](http://i.stack.imgur.com/jYouK.png)](http://i.stack.imgur.com/jYouK.png)

I also use matplotlib 1.5.0 and python 2.7 and I always get the same plot
regardless of how many times the script is executed.

