From: Humufr <hu...@ya...> - 2005-01-20 03:50:44
|
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 |
From: Humufr <hu...@ya...> - 2005-01-20 16:50:43
|
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 |
From: John H. <jdh...@ac...> - 2005-01-20 17:44:17
|
>>>>> "Humufr" == Humufr <hu...@ya...> writes: Humufr> but if you use axis only without redefine gca limit that Humufr> don't work: Humufr> from pylab import * from matplotlib.patches import Humufr> Rectangle axis([0,10],[0,10]) ax = gca() p = Humufr> Rectangle((1,1),3,3,fill=False) ax.add_patch(p) I think you screwed up the "axis" syntax. What you mean (I think) is: 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) show() Humufr> I understand that gca return an instance but perhaps that Humufr> will be a good idea if by default that will use the axis Humufr> of the courrant figure and not [0,1,0,1]. I'm a little confused here. gca returns the current axes (note axis and axes are different commands and have different meanings). The default axes is 2 >>> ax = gca() 3 >>> ax.get_position() Out[3]: [0.125, 0.10999999999999999, 0.77500000000000002, 0.79000000000000004] Can you clarify your meaning? axis set the view limits of the current axes. The view limits are in data coordinates, and these are the same limits that are controlled by xlim and ylim. axes sets the position of the axes (the frame in which your plots are made) and these coordinates are in figure coords -- 0,0 is lower left of the figure and 1,1 is upper right. JDH |
From: Humufr <hu...@ya...> - 2005-01-20 19:17:13
|
John Hunter wrote: >>>>>>"Humufr" == Humufr <hu...@ya...> writes: >>>>>> >>>>>> > > > Humufr> but if you use axis only without redefine gca limit that > Humufr> don't work: > > Humufr> from pylab import * from matplotlib.patches import > Humufr> Rectangle axis([0,10],[0,10]) ax = gca() p = > Humufr> Rectangle((1,1),3,3,fill=False) ax.add_patch(p) > >I think you screwed up the "axis" syntax. What you mean (I think) is: > > 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) > show() > > yes sorry I did mistake in my mail but the result is the same. I can't draw the rectangle where I want. To do this I had to set the xlim and ylim manually. > Humufr> I understand that gca return an instance but perhaps that > Humufr> will be a good idea if by default that will use the axis > Humufr> of the courrant figure and not [0,1,0,1]. > >I'm a little confused here. gca returns the current axes (note axis >and axes are different commands and have different meanings). The >default axes is > >2 >>> ax = gca() > >3 >>> ax.get_position() >Out[3]: [0.125, 0.10999999999999999, 0.77500000000000002, 0.79000000000000004] > >Can you clarify your meaning? axis set the view limits of the current >axes. The view limits are in data coordinates, and these are the same >limits that are controlled by xlim and ylim. axes sets the position >of the axes (the frame in which your plots are made) and these >coordinates are in figure coords -- 0,0 is lower left of the figure >and 1,1 is upper right. > > 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). Thanks, Nicolas |
From: John H. <jdh...@ac...> - 2005-01-20 20:13:18
|
>>>>> "Humufr" == Humufr <hu...@ya...> writes: Humufr> I understand your point but I think that to draw on object Humufr> inside a figure, using some relative coordinate are not Humufr> very convenient. You add to play with the data coordinates Humufr> and the figures coordinates. That can be useful for some Humufr> objects but very often some people would like to plot a Humufr> rectangle (or what do you want) with the data corrdinate Humufr> and it's very disturbing at the beginning the way that Humufr> patches is working. I don't know if I'm clear this time Humufr> (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 |
From: Jochen V. <vo...@se...> - 2005-01-23 14:58:13
|
Hello John, On Thu, Jan 20, 2005 at 02:07:26PM -0600, John Hunter wrote: > p =3D Rectangle((1,1),3,3,fill=3DFalse) > ax.add_patch(p) >=20 > your rectangle is in *data coordinates* and it is where it should be > (center at 1,1 and width=3Dheight=3D3). 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 | =20 | width and height are width and height of rectangle | =20 | fill is a boolean indicating whether to fill the rectangle All the best, Jochen --=20 http://seehuhn.de/ |