|
From: jonasr <jon...@we...> - 2012-09-06 21:50:22
|
Hello, i spotted a bug in the Rectangle function when plotting with multiple subplot, here is a source code example: #!/usr/bin/env python # -*- coding: utf-8 -*- from matplotlib.pyplot import * from numpy import * import sys, os def main(): f, axs = subplots(1,2) x=arange(0,10,0.001) y=sin(x) axs[0].plot(x,y,"blue")#,alpha=1) axs[1].plot(x,y,"blue",alpha=1) rect = Rectangle((0,0), 1, 1, facecolor="blue",alpha=1) axs[0].add_patch(rect) axs[1].add_patch(rect) show() return 0 if __name__ == '__main__': main() this script should plot two sin functions and a rectangle in both subplots . the rectangle doesn't seem to appear until i move the area from the left subplot (where the rectangle should appear) over to the second subplot. here is an example how it looks like: http://www.imagebanana.com/view/hzm8bjro/example.png if i remove the command axs[1].add_patch(rect) the problem doesn't seem to appear my current matplotlib version is: '1.1.1rc' os is ubuntu 12.04 greetz jonas -- View this message in context: http://matplotlib.1069221.n5.nabble.com/Rectangle-Bug-tp38825.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
|
From: Benjamin R. <ben...@ou...> - 2012-09-07 03:57:34
|
On Thursday, September 6, 2012, jonasr wrote: > Hello, > > i spotted a bug in the Rectangle function when plotting with multiple > subplot, here is a source code example: > > #!/usr/bin/env python > # -*- coding: utf-8 -*- > > from matplotlib.pyplot import * > from numpy import * > import sys, os > > def main(): > f, axs = subplots(1,2) > > x=arange(0,10,0.001) > y=sin(x) > axs[0].plot(x,y,"blue")#,alpha=1) > axs[1].plot(x,y,"blue",alpha=1) > > rect = Rectangle((0,0), 1, 1, facecolor="blue",alpha=1) > axs[0].add_patch(rect) > axs[1].add_patch(rect) > > show() > return 0 > > if __name__ == '__main__': > main() > > this script should plot two sin functions and a rectangle in both subplots > . > the rectangle doesn't seem to appear until i move the area from the left > subplot (where the rectangle should appear) > over to the second subplot. > here is an example how it looks like: > http://www.imagebanana.com/view/hzm8bjro/example.png > > if i remove the command > axs[1].add_patch(rect) > the problem doesn't seem to appear > > my current matplotlib version is: '1.1.1rc' > os is ubuntu 12.04 > > greetz jonas > > > > Not a bug. An artist, such as the rectangle patch, can only reliably work in one axes object at a time. It can not be in two places at once. Make two rectangles and attach each to an axes, and it will work. Cheers! Ben Root |
|
From: jonasr <jon...@we...> - 2012-09-07 06:35:30
|
That seems to work, thank you. I would have thought that the add_patch function creates two seperate objects independent of the defined Rectangle. greets jonas -- View this message in context: http://matplotlib.1069221.n5.nabble.com/Rectangle-Bug-tp38825p38828.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
|
From: Eric F. <ef...@ha...> - 2012-09-07 06:43:01
|
On 2012/09/06 8:35 PM, jonasr wrote: > That seems to work, thank you. > > I would have thought that the add_patch function creates two seperate > objects independent of the defined Rectangle. add_patch doesn't create any objects; it just attaches the axes to the patch in both directions: a reference to the patch object is appended to a list of axes artists, and the patch object gets a reference to the axes. Fortunately, python has garbage collection to handle such circular references. Eric > > greets jonas |
|
From: Phil E. <pel...@gm...> - 2012-09-07 07:03:13
|
This seems to a be common misconception... I guess in future, we could add a check to the add_patch method to see if the given artist already has an associated Axes, and if it does, emit a warning. On 7 September 2012 07:42, Eric Firing <ef...@ha...> wrote: > On 2012/09/06 8:35 PM, jonasr wrote: > > That seems to work, thank you. > > > > I would have thought that the add_patch function creates two seperate > > objects independent of the defined Rectangle. > > add_patch doesn't create any objects; it just attaches the axes to the > patch in both directions: a reference to the patch object is appended to > a list of axes artists, and the patch object gets a reference to the > axes. Fortunately, python has garbage collection to handle such > circular references. > > Eric > > > > > greets jonas > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |
|
From: Eric F. <ef...@ha...> - 2012-09-07 07:28:08
|
On 2012/09/06 9:03 PM, Phil Elson wrote: > This seems to a be common misconception... > > I guess in future, we could add a check to the add_patch method to see > if the given artist already has an associated Axes, and if it does, emit > a warning. It's not just patches; but I think a single warning in Artist.add_axes would do it, perhaps at the cost of generating an unnecessary warning for some legitimate use case. Eric > > > > On 7 September 2012 07:42, Eric Firing <ef...@ha... > <mailto:ef...@ha...>> wrote: > > On 2012/09/06 8:35 PM, jonasr wrote: > > That seems to work, thank you. > > > > I would have thought that the add_patch function creates two seperate > > objects independent of the defined Rectangle. > > add_patch doesn't create any objects; it just attaches the axes to the > patch in both directions: a reference to the patch object is appended to > a list of axes artists, and the patch object gets a reference to the > axes. Fortunately, python has garbage collection to handle such > circular references. > > Eric > > > > > greets jonas > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. > Discussions > will include endpoint security, mobile security and the latest in > malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > <mailto:Mat...@li...> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > |