trace a rectangle

I understand your point but I think that to draw on object

    > inside a figure, using some relative coordinate are not
    > very convenient. You add to play with the data coordinates
    > and the figures coordinates. That can be useful for some
    > objects but very often some people would like to plot a
    > rectangle (or what do you want) with the data corrdinate
    > and it's very disturbing at the beginning the way that
    > patches is working. I don't know if I'm clear this time
    > (my english is very poor sometimes).

Yes, apparently there is something of a language barrier -- my french
is not so good either, sigh.

But I just want to reiterate, you are not using relative coords for
the rectangle in the example below. When you do the following,

    from pylab import *
    from matplotlib.patches import Rectangle
    ax = gca()
    p = Rectangle((1,1),3,3,fill=False)
    ax.add_patch(p)

your rectangle is in *data coordinates* and it is where it should be
(center at 1,1 and width=height=3). The problem is that your axis
"view" limits are not set properly (if you use the pan and zoom
features of the toolbar to move your view limits you'll see the
rectangle where it should be. Only the plot commands (plot, scatter,
etc,....) call autoscale_view to set the view limits (add_patch does
not), so you need to set the axis limits yourself.

  axis([0,10,0,10])

In summary, the rectangle is being added in the right coordinate
system (data coords) but the view limits are not automatically
autoscaled unless you issue a plot command. I choose not to do
autoscale every time a patch is added for performance reasons -- if
you are savvy enough to call add_patch, I assume you are savvy enough
to call set_xlim or set_ylim as appropriate for your data.

JDH

Hello John,

    p = Rectangle((1,1),3,3,fill=False)
    ax.add_patch(p)

your rectangle is in *data coordinates* and it is where it should be
(center at 1,1 and width=height=3).

I think this is wrong. The lower-left corner is at (1,1), not
the center. At least help(Rectangle) states

> __init__(self, xy, width, height, **kwargs)
> xy is an x,y tuple lower, left
>
> width and height are width and height of rectangle
>
> fill is a boolean indicating whether to fill the rectangle

All the best,
Jochen

···

On Thu, Jan 20, 2005 at 02:07:26PM -0600, John Hunter wrote:
--
http://seehuhn.de/