trace a rectangle

Hi,

I have a problem to draw a rectangle:

The first is that I can't arrive to draw a rectangle with ipython -pylab, the script who work when it's launch independantly is not working interactively. The rectangle is not draw. Perhaps it's normal but I don't think.

The second problem I have is to draw a rectangle at a certain position with certain height and width. It's seems (at least when I tried to use it) that the position must be done relatively at the window and not from the plot. It's not very convenient because if I have a plot draw between 1 and 100 in x and y, to draw the rectangle I add to use something between 0 and 1 so I had to rescale the rectangle.

Thanks,

    Nicolas

Hi,
so I found some answer to the second problem, to draw a rectangle at a certain place you add to define the limit for gca instance, by default the limit of the figure are not use:

from pylab import *
from matplotlib.patches import Rectangle
ax = gca()
set(gca(),'xlim',[0,10],'ylim',[0,10])
p = Rectangle((1,1),3,3,fill=False)
ax.add_patch(p)

or more pythonic:

from pylab import *
from matplotlib.patches import Rectangle
ax = gca()
ax.set_xlim([0,10])
ax.set_ylim([0,10])
p = Rectangle((1,1),3,3,fill=False)
ax.add_patch(p)

but if you use axis only without redefine gca limit that don't work:

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

I understand that gca return an instance but perhaps that will be a good idea if by default that will use the axis of the courrant figure and not [0,1,0,1].

Thanks,

          Nicolas

Humufr wrote:

···

            Hi,

I have a problem to draw a rectangle:

The first is that I can't arrive to draw a rectangle with ipython -pylab, the script who work when it's launch independantly is not working interactively. The rectangle is not draw. Perhaps it's normal but I don't think.

The second problem I have is to draw a rectangle at a certain position with certain height and width. It's seems (at least when I tried to use it) that the position must be done relatively at the window and not from the plot. It's not very convenient because if I have a plot draw between 1 and 100 in x and y, to draw the rectangle I add to use something between 0 and 1 so I had to rescale the rectangle.

Thanks,

   Nicolas