FAQ
The automatic placement functionality of legend() is nice. I'd like to
make use of it to place a box with just a title or title and comment
(ie, some text) but no lines or legend entries. Does anyone know a
way to do this?

Search Discussions

  • Christopher Barrington-Leigh at Jun 29, 2011 at 3:44 pm
    I still need help with this.

    I'd like to have the Sample A box place itself in the optimal empty space, so as not to overly any graphing elements (if possible):



    import numpy.random
    import matplotlib.pyplot as plt

    fig = plt.figure(1, figsize=(5,5))
    fig.clf()

    ax = fig.add_subplot(111)
    ax.set_aspect(1)

    x1 = -1 + numpy.random.randn(100)
    y1 = -1 + numpy.random.randn(100)
    x2 = 1. + numpy.random.randn(100)
    y2 = 1. + numpy.random.randn(100)

    ax.scatter(x1, y1, color="r")
    ax.scatter(x2, y2, color="g")

    bbox_props = dict(boxstyle="round", fc="w", ec="0.5", alpha=0.9)
    ax.text(-2, -2, "Sample A", ha="center", va="center", size ,
    bbox»ox_props)

    plt.draw()
    plt.show()
  • Cousin Stanley at Jun 29, 2011 at 6:41 pm

    Christopher Barrington-Leigh wrote:

    I'd like to have the Sample A box place itself
    in the optimal empty space, so as not to overlay
    any graphing elements (if possible):
    ....
    A simple alternative might be to place the label
    just outside of the plot region either at the top
    or the bottom of the plot instead of finding
    an open area in which to place the label ....

    def extremes( x1 , y1 , x2 , y2 ) :

    min_x1 = min( x1 )
    min_y1 = min( y1 )

    max_x1 = max( x1 )
    max_y1 = max( y1 )

    min_x2 = min( x2 )
    min_y2 = min( y2 )

    max_x2 = max( x2 )
    max_y2 = max( y2 )

    min_x = min( min_x1 , min_x2 )
    min_y = min( min_y1 , min_y2 )

    max_x = max( max_x1 , max_x2 )
    max_y = max( max_y1 , max_y2 )

    aminx = min_x
    aminy = min_y - 1.4

    amaxx = max_x
    amaxy = max_y + 1.4

    return aminx , aminy , amaxx , amaxy


    # bump up the plot size a bit

    fig = plt.figure( 1 , figsize = ( 6 , 6 ) )

    ....

    aminx , aminy , amaxx , amaxy = extremes( x1 , y1 , x2 , y2 )

    ....

    # label at top center

    ax.text( 0 , amaxy , "Sample A" , ha = "center" , va = "center" ,
    size = 16 , bbox = bbox_props )


    --
    Stanley C. Kitching
    Human Being
    Phoenix, Arizona

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedApr 27, '11 at 12:25a
activeJun 29, '11 at 6:41p
posts3
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase