## matplotlib-users

 [Matplotlib-users] line, From: jonasr - 2011-06-15 22:35:46 ```hello, a lot of matplotlib examples i saw included the usage of line, i.e. from pylab import * import time ion() tstart = time.time() # for profiling x = arange(0,2*pi,0.01) # x-array line, = plot(x,sin(x)) for i in arange(1,200): line.set_ydata(sin(x+i/10.0)) # update the data draw() # redraw the canvas print 'FPS:' , 200/(time.time()-tstart) can anybody explain to me whats the difference between line and line, ? -- View this message in context: http://old.nabble.com/line%2C-tp31855827p31855827.html Sent from the matplotlib - users mailing list archive at Nabble.com. ```
 Re: [Matplotlib-users] line, From: Eric Firing - 2011-06-15 22:43:00 ```On 06/15/2011 12:35 PM, jonasr wrote: > > hello, > > a lot of matplotlib examples i saw included the usage of line, i.e. > > from pylab import * > import time > > ion() > > tstart = time.time() # for profiling > x = arange(0,2*pi,0.01) # x-array > line, = plot(x,sin(x)) > for i in arange(1,200): > line.set_ydata(sin(x+i/10.0)) # update the data > draw() # redraw the canvas > > print 'FPS:' , 200/(time.time()-tstart) > > can anybody explain to me whats the difference between line and line, ? > plot returns a list of lines, and line, = plot(...) returns the first one (which in your case is the only one) It is the same as line = plot(...)[0] It is a special case of Python's sequence unpacking, e.g.: a, b, c = [1, 2, 3] Eric ```
 Re: [Matplotlib-users] line, From: jonasr - 2011-06-15 22:53:56 ```Thank you for the fast reply, according to you line and "line," shouldt make a difference in this case, i tried the code with line and line, and it only works with line, ? so you say if i use a=[1,2,3] then b, = a should be 1 ? i just get the error message to many values to unpack ... efiring wrote: > > On 06/15/2011 12:35 PM, jonasr wrote: >> >> hello, >> >> a lot of matplotlib examples i saw included the usage of line, i.e. >> >> from pylab import * >> import time >> >> ion() >> >> tstart = time.time() # for profiling >> x = arange(0,2*pi,0.01) # x-array >> line, = plot(x,sin(x)) >> for i in arange(1,200): >> line.set_ydata(sin(x+i/10.0)) # update the data >> draw() # redraw the canvas >> >> print 'FPS:' , 200/(time.time()-tstart) >> >> can anybody explain to me whats the difference between line and line, ? >> > > plot returns a list of lines, and > > line, = plot(...) > > returns the first one (which in your case is the only one) > > It is the same as > > line = plot(...)[0] > > It is a special case of Python's sequence unpacking, e.g.: > > a, b, c = [1, 2, 3] > > Eric > > ------------------------------------------------------------------------------ > EditLive Enterprise is the world's most technically advanced content > authoring tool. Experience the power of Track Changes, Inline Image > Editing and ensure content is compliant with Accessibility Checking. > http://p.sf.net/sfu/ephox-dev2dev > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- View this message in context: http://old.nabble.com/line%2C-tp31855827p31855959.html Sent from the matplotlib - users mailing list archive at Nabble.com. ```
 Re: [Matplotlib-users] line, From: Eric Firing - 2011-06-15 23:30:46 ```On 06/15/2011 12:53 PM, jonasr wrote: > > Thank you for the fast reply, according to you line and "line," shouldt make > a difference in this case, No, that's not what I said. Using "line" gives you a list with one element, but using "line," gives you the element itself, not the list. > i tried the code with line and line, and it only works with line, ? > > so you say if i use > a=[1,2,3] > then b, = a should be 1 ? i just get the error message to many values to > unpack ... Yes, when you use this automatic unpacking the number of items has to match. You can only use a, b = rhs when you *know* rhs will be a sequence with two, and only two, elements. Eric > > > > efiring wrote: >> >> On 06/15/2011 12:35 PM, jonasr wrote: >>> >>> hello, >>> >>> a lot of matplotlib examples i saw included the usage of line, i.e. >>> >>> from pylab import * >>> import time >>> >>> ion() >>> >>> tstart = time.time() # for profiling >>> x = arange(0,2*pi,0.01) # x-array >>> line, = plot(x,sin(x)) >>> for i in arange(1,200): >>> line.set_ydata(sin(x+i/10.0)) # update the data >>> draw() # redraw the canvas >>> >>> print 'FPS:' , 200/(time.time()-tstart) >>> >>> can anybody explain to me whats the difference between line and line, ? >>> >> >> plot returns a list of lines, and >> >> line, = plot(...) >> >> returns the first one (which in your case is the only one) >> >> It is the same as >> >> line = plot(...)[0] >> >> It is a special case of Python's sequence unpacking, e.g.: >> >> a, b, c = [1, 2, 3] >> >> Eric >> >> ------------------------------------------------------------------------------ >> EditLive Enterprise is the world's most technically advanced content >> authoring tool. Experience the power of Track Changes, Inline Image >> Editing and ensure content is compliant with Accessibility Checking. >> http://p.sf.net/sfu/ephox-dev2dev >> _______________________________________________ >> Matplotlib-users mailing list >> Matplotlib-users@... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> >> > ```