How do I set axes to add text outside a plot?
Question: (Using python3.4)

This is the code I'm using to plot. I'm trying to add additional text which
can help explain what this plot is about.

    
    
    import matplotlib.pyplot as plt
    import numpy as np
    somecode.....
    somecode.....
    xv=np.array(x1)
    yv=np.array(y1)
    txt='''
    Text to be printed outside the plot
    Text to be printed outside the plot
    Text to be printed outside the plot
    Text to be printed outside the plot
    Text to be printed outside the plot
    '''
    plt.figure(1)
    plt.scatter(yv,zv, label="Cap vs Percentage Diff", color="m")
    plt.xlabel('Latest Cap in FF')
    plt.ylabel('Percentage Diff')
    plt.title('Variable Cap')
    plt.grid(True)
    plt.legend()
    plt.text(0.95, 0.95, txt)
    

I used plt.text to print the text 0.95 below the X-axis the and 0.95 away from
Y axis. But matplotlib is picking the co-ordinates relative to the graph.

This issue is reported on couple of other threads and most of the answers are
explained using plt.text format.

Is there a way to print text beyond the axis?

As a work around I'm currently adding this information to plt.xlabel so that
it can be printed under the x-axis label. But, I'd like to know the
possibilities to add text outside the plot by not specifying the co-ordinates.

Reason I don't want to use/Specify X, Y co-ordinates is, XY coordinates can be
negative values in the data I'm reading in.

I tried to understand the syntax and usage from documentation but it is far
beyond my expertise as I started using python fairly couple of weeks ago.

Appreciate if any one can explain/tell how to use text and figtext to add data
outside the plot.

And does both text and figtext need axes info?

Current plot displays the image without the text I want to add outside the
plot

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

Required plot style: I'd like to the stddev, avg, min and max under the
x-label of subplot:

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

Thanks

Edit 1: Adding original code.

    
    
    import matplotlib
    import sys
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt
    import numpy as np
    import os
    
    x1=[1, 2, 3, 4]
    y1=[5, 6, 7, 8]
    z1=[9, 10 ,11, 12]
    
    xv=np.array(x1)
    yv=np.array(y1)
    zv=np.array(z1)
    #Find Max, Min, Avg and StdDev for the delta(C) i.e. zv numpy array
    MaxCapDiff      =str (np.amax(zv))
    MinCapDiff      =str (np.amin(zv))
    AvgOfCapDiff        =str (np.average(zv))
    StdDevOfCapDiff     =str (np.std(zv))
    
    print ('Max Cap Diff in Percent:'+MaxCapDiff) print ('Min Cap Diff in          Percent:'+MinCapDiff) print ('Avg of Cap Difference  :'+AvgOfCapDiff)
    print ('STD DEV of Cap Diff    :'+StdDevOfCapDiff)
    
    plt.figure(1)
    plt.subplot(211)
    plt.scatter(xv,yv, label="Cap vs Cap")
    plt.xlabel('Golden Cap in (FF)')
    plt.ylabel('Latest Cap in (FF)')
    plt.title('Cap Comparison')
    plt.legend()
    
    plt.subplot(212)
    plt.scatter(yv,zv, label="Cap vs Percentage Diff", color="m")
    plt.xlabel('Latest cap in (FF)') plt.ylabel('Percentage Diff')
    plt.title('Variable Cap')
    plt.legend()
    plt.tight_layout()
    plt.savefig('plot.jpg')
    plt.show()
    


Answer: The function you want to use is annotate, and the [documentation can be found
here](http://matplotlib.org/users/annotations_intro.html.).

I can't reproduce your plots with the code above but you should be able to use
the code below. The key here is to set `annotation_clip` to `False` in order
to alow the text to be dispayed outside of the axes

    
    
    fig, ax = plt.subplots()
    plt.scatter(yv,zv, label="Cap vs Percentage Diff", color="m")
    plt.xlabel('Latest Cap in FF')
    plt.ylabel('Percentage Diff')
    plt.title('Variable Cap')
    plt.grid(True)
    plt.legend()
    
    ##insert the line below:
    ax.annotate('Insert text here',xy=(0,0),xytext=(x1,y1), annotation_clip=False)
    
    plt.show()
    

Note that you will need to change the values of `x1` and `y1` in the `xytext`
to the position that you would like the text to be. This might require some
trial and error to get it exactly right.

