## Re: [Matplotlib-users] Specifying X,Y Pairs For Line Plots

 Re: [Matplotlib-users] Specifying X,Y Pairs For Line Plots From: Christopher Barker - 2007-11-26 22:19:37 ```Rich Shepard wrote: >> x,y = zip(*[(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)]) or better yet -- work with numpy arrays from the beginning: Either put x an y into separate arrays (which is what MPL expects), or if you like X and Y begin together (I do): points = numpy.array([(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)]) x = points[:,0] y = points[:,1] and: p0 = points[0] p1 = points[1] etc. etc. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@... ```

 [Matplotlib-users] Specifying X,Y Pairs For Line Plots From: Rich Shepard - 2007-11-25 17:16:35 ``` I need to plot trapezoids as well as left- and right-shouldered straight line plots. If I specify separate lists for the x values and their corresponding y values, the plots are generated and displayed as needed. However, I cannot specify the points as a list of tuples and have matplotlib accept them. Example: x,y = [(15,0.0), (30,1.0), (70,1.0) (85,0.0)] p.plot (x,y) Yields: Traceback (most recent call last): File "trapezoid.py", line 4, in ? x,y = [(15,0.0), (30,1.0), (70,1.0) (85,0.0)] TypeError: 'tuple' object is not callable I don't see how to do this in the User Guide, but I'm sure there must be a way. Please pass me a pointer on how to accomplish this. Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation ; Voice: 503-667-4517 Fax: 503-667-8863 ```
 Re: [Matplotlib-users] Specifying X,Y Pairs For Line Plots From: Darren Dale - 2007-11-25 17:48:09 ```On Sunday 25 November 2007 12:15:54 pm Rich Shepard wrote: > x,y = [(15,0.0), (30,1.0), (70,1.0) (85,0.0)] you need a "," after that "(70,1.0)" ```
 Re: [Matplotlib-users] Specifying X,Y Pairs For Line Plots From: Rich Shepard - 2007-11-25 18:00:18 ```On Sun, 25 Nov 2007, Darren Dale wrote: > you need a "," after that "(70,1.0)" Thanks, Darren. Not enough caffine, I guess. However, now I get: Traceback (most recent call last): File "trapezoid.py", line 4, in ? x,y = [(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)] ValueError: too many values to unpack which tells me something is still not correct. Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation ; Voice: 503-667-4517 Fax: 503-667-8863 ```
 Re: [Matplotlib-users] Specifying X,Y Pairs For Line Plots From: Jouni K - 2007-11-25 18:37:56 ```Rich Shepard writes: > x,y = [(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)] > ValueError: too many values to unpack You are looking for the classic "unzip" trick: x,y = zip(*[(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)]) -- Jouni ```
 Re: [Matplotlib-users] Specifying X,Y Pairs For Line Plots From: Rich Shepard - 2007-11-25 19:13:03 ```On Sun, 25 Nov 2007, Jouni K Sepp=E4nen wrote: > You are looking for the classic "unzip" trick: > x,y =3D zip(*[(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)]) Jouni, That's totally new to me. I'll go find out what it is and how it works i= ts magic. Thank you, Rich --=20 Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation ; Voice: 503-667-4517 Fax: 503-667-8863```
 Re: [Matplotlib-users] Specifying X,Y Pairs For Line Plots From: Rich Shepard - 2007-11-25 20:18:58 ```On Sun, 25 Nov 2007, Jouni K Sepp=E4nen wrote: > x,y =3D zip(*[(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)]) Jouni, Thank you for pointing this out to me. I see that it's a builtin functio= n similar to map that assembles the first element of each tuple into a list for the first variable, and the second element of each tuple into a list fo= r the second variable. How useful for my plotting needs! Rich --=20 Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation ; Voice: 503-667-4517 Fax: 503-667-8863```
 Re: [Matplotlib-users] Specifying X,Y Pairs For Line Plots From: Christopher Barker - 2007-11-26 22:19:37 ```Rich Shepard wrote: >> x,y = zip(*[(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)]) or better yet -- work with numpy arrays from the beginning: Either put x an y into separate arrays (which is what MPL expects), or if you like X and Y begin together (I do): points = numpy.array([(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)]) x = points[:,0] y = points[:,1] and: p0 = points[0] p1 = points[1] etc. etc. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@... ```
 Re: [Matplotlib-users] Specifying X,Y Pairs For Line Plots From: Rich Shepard - 2007-11-26 22:45:23 ```On Mon, 26 Nov 2007, Christopher Barker wrote: > or better yet -- work with numpy arrays from the beginning: Chris, These values are retrieved from widgets on a notebook page and the plot will be used to display them on that tab. It would take more code to convert those values to a numpy array. Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation ; Voice: 503-667-4517 Fax: 503-667-8863 ```