|
From: Mark B. <ma...@gm...> - 2006-07-12 20:16:38
|
I am following up on the discussion of passing a single 2D array to plot. Wouldn't it make more sense that, in Python array style, if you give it a single N x K argument you plot rows against the first row? On the same token, it would be really nice if contour, pcolor and image take as an x and y argument not only a matrix but just a 1D row. This should be really easy and would be very useful. In fact, if more people want it I can submit a patch for the latter one, Mark ------------------------------ > > Message: 4 > Date: Wed, 12 Jul 2006 14:38:46 -0400 > From: Alan G Isaac <ai...@am...> > Subject: Re: [Matplotlib-users] ANN: matplotlib-0.87.4 (bugfix release > for enthon) > To: mat...@li... > Message-ID: <Mah...@am...> > Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-1 > > On Wed, 12 Jul 2006, Eric Firing apparently wrote: > > In the single-argument NxK case, I think matlab plots > > subsequent columns against the first column. Is this what > > you would like? > > Yes. > > Cheers, > Alan Isaac > > |
|
From: Mark B. <ma...@gm...> - 2006-07-13 08:35:45
|
Eric - To be honest, I think the native array storage order matters a lot. When you have a large dataset, transposing the matrix is not a cheap command. But I also understand the logic of plotting column against column. However, a 1D vector in Python is by default a row, while in Matlab it is a column. What are you going to do if a 1D row is given as first argument and a matrix as second??? I don't like the Matlab model when one matrix is passed. It should really plot the first column along the x-axis and all the other columns along y. Like your 2nd option below, but with NxM array. It would then be very nice to have an optional argument to the function to plot all rows against the first row. That would be very easy to implement and keep everybody happy. As you said, there will be many more opinions, Mark To summarize, the options seem to be: > > 1) Leave plot argument parsing alone. > 2) Accept an Nx2 array in place of a pair of arguments containing x and y. > > 3) Implement the Matlab model. > 4) Implement the Matlab model, but taking rows instead of columns in an > X or Y array that is 2-D. > > I am open to arguments, but my preference is the Matlab model. I don't > think that the difference in native array storage order matters much. > It is more important to have the API at the plot method and function > level match the way people think. > > Eric > > |
|
From: Stefan v. d. W. <st...@su...> - 2006-07-13 09:40:36
|
On Thu, Jul 13, 2006 at 10:34:11AM +0200, Mark Bakker wrote: > To be honest, I think the native array storage order matters a lot. > When you have a large dataset, transposing the matrix is not a cheap > command. If you use numpy, transposing is cheap. You see it when you try import numpy as N z =3D N.random.random([1000,1000]) print "Transposing..." for x in range(10000): z.transpose() in the latest SVN of numpy, they also have the convencience-shorthand of z.T (which calls z.transpose()). Regards St=E9fan |
|
From: Darren D. <dd...@co...> - 2006-07-13 11:23:47
|
On Thursday 13 July 2006 4:34 am, Mark Bakker wrote: > To be honest, I think the native array storage order matters a lot. [...] > However, a 1D vector in Python is by default a row, while in Matlab it is a > column. > What are you going to do if a 1D row is given as first argument and a > matrix as second??? matplotlib's load command returns a row vector, regardless of whether the data is Mx1 or 1xM. |
|
From: Eric F. <ef...@ha...> - 2006-07-13 17:54:48
|
Stefan van der Walt wrote: > On Thu, Jul 13, 2006 at 10:34:11AM +0200, Mark Bakker wrote: > >>To be honest, I think the native array storage order matters a lot. >>When you have a large dataset, transposing the matrix is not a cheap >>command. > > > If you use numpy, transposing is cheap. You see it when you try > > import numpy as N > z = N.random.random([1000,1000]) > print "Transposing..." > for x in range(10000): z.transpose() > > in the latest SVN of numpy, they also have the convencience-shorthand > of z.T (which calls z.transpose()). It is especially cheap in comparison to everything else that happens when one plots with matplotlib! Utterly negligible. Eric |
|
From: Eric F. <ef...@ha...> - 2006-07-13 18:06:11
|
Mark Bakker wrote: > Eric - > > To be honest, I think the native array storage order matters a lot. > When you have a large dataset, transposing the matrix is not a cheap > command. No, in this context it is very cheap relative to the rest of the plotting. > > But I also understand the logic of plotting column against column. > However, a 1D vector in Python is by default a row, while in Matlab it > is a column. > What are you going to do if a 1D row is given as first argument and a > matrix as second??? No problem. It is easy to treat a 1D array as either a column or a row, depending on whether one has chosen option 3 or option 4. This could even be controlled by an rc option and/or a kwarg, but I think this is a bad idea. Better to just pick 3 or 4 and stick with it, using transpose when needed. Keep things simple and explicit. > > I don't like the Matlab model when one matrix is passed. It should > really plot the first column along > the x-axis and all the other columns along y. Like your 2nd option > below, but with NxM array. > It would then be very nice to have an optional argument to the function > to plot all rows against the first row. That would be very easy to > implement and keep everybody happy. To make sure I understand you: you are suggesting a kwarg that tells the plot command to plot subsequent rows (or it could be columns) against the first? Something like plot(Z, xvec='row') plot(Z, xvec='column') plot(Z, xvec=None) #default: present behavior But why is this better than the following? plot(Z[0,:], Z[1:,:]) The latter would accomplish the same, be completely consistent with option 4, be completely explicit and unambiguous, require no more typing than using a kwarg, require no extra logic in the plot code, and require no extra documentation for the plot command. Eric > > As you said, there will be many more opinions, > > Mark > > > > To summarize, the options seem to be: > > 1) Leave plot argument parsing alone. > 2) Accept an Nx2 array in place of a pair of arguments containing x > and y. > > 3) Implement the Matlab model. > 4) Implement the Matlab model, but taking rows instead of columns in an > X or Y array that is 2-D. > > I am open to arguments, but my preference is the Matlab model. I don't > think that the difference in native array storage order matters much. > It is more important to have the API at the plot method and function > level match the way people think. > > Eric > > > > ------------------------------------------------------------------------ > > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > > ------------------------------------------------------------------------ > > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
|
From: Mark B. <ma...@gm...> - 2006-07-14 10:02:42
|
You are right, concerning your comment below. That will work just fine, Mark On 7/13/06, Eric Firing <ef...@ha...> wrote: > > > > But why is this better than the following? > > plot(Z[0,:], Z[1:,:]) > > The latter would accomplish the same, be completely consistent with > option 4, be completely explicit and unambiguous, require no more typing > than using a kwarg, require no extra logic in the plot code, and require > no extra documentation for the plot command. > > Eric > > > > As you said, there will be many more opinions, > > > > Mark > > > > > > > > To summarize, the options seem to be: > > > > 1) Leave plot argument parsing alone. > > 2) Accept an Nx2 array in place of a pair of arguments containing x > > and y. > > > > 3) Implement the Matlab model. > > 4) Implement the Matlab model, but taking rows instead of columns in > an > > X or Y array that is 2-D. > > > > I am open to arguments, but my preference is the Matlab model. I > don't > > think that the difference in native array storage order matters > much. > > It is more important to have the API at the plot method and function > > level match the way people think. > > > > Eric > > > > > > > > ------------------------------------------------------------------------ > > > > > > > ------------------------------------------------------------------------- > > Using Tomcat but need to do more? Need to support web services, > security? > > Get stuff done quickly with pre-integrated technology to make your job > easier > > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Matplotlib-users mailing list > > Mat...@li... > > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > |
|
From: Eric F. <ef...@ha...> - 2006-12-10 02:28:48
|
Below is the last (or nearly so) message of a thread from last summer. I have now implemented option 3 in svn, so: If y is 2-D, plot(y) plots the columns of y against the row-index. If x is 1-D and y is 2-D, plot(x,y) plots the columns of y against x. (In this case, x can also be 2-D if it is a single column.) If x is 2-D and y is 1-D, plot(x,y) plots y against each successive column of x. (Again, y can also be a single column.) If x and y are both 2-D, plot(x,y) plots columns of y against the corresponding columns of x. They must have the same number of columns. All of this is consistent with Matlab, as far as I know. Apart from this compatibility aspect, the design tradeoff is between the appeal of plotting rows, on the grounds that they correspond to C storage order, versus the appeal of plotting columns, on the grounds that one tends to think of columns in a table as the natural vectors to be plotted. I don't think it makes much difference in efficiency; transposing is cheap in numpy. It is possible that plotting non-contiguous values triggers an additional array copy somewhere in the chain of operations. I have not tried to figure out whether it does, or what the time penalty would be if it does, but I strongly doubt it would be a noticeable fraction of the total plot generation time. The changes are only very lightly tested so far, so please look for bugs. Eric Mark Bakker wrote: > You are right, concerning your comment below. > That will work just fine, > Mark > > On 7/13/06, *Eric Firing* <ef...@ha... > <mailto:ef...@ha...>> wrote: > > > > But why is this better than the following? > > plot(Z[0,:], Z[1:,:]) > > The latter would accomplish the same, be completely consistent with > option 4, be completely explicit and unambiguous, require no more typing > than using a kwarg, require no extra logic in the plot code, and > require > no extra documentation for the plot command. > > Eric > > > > As you said, there will be many more opinions, > > > > Mark > > > > > > > > To summarize, the options seem to be: > > > > 1) Leave plot argument parsing alone. > > 2) Accept an Nx2 array in place of a pair of arguments > containing x > > and y. > > > > 3) Implement the Matlab model. > > 4) Implement the Matlab model, but taking rows instead of > columns in an > > X or Y array that is 2-D. > > > > I am open to arguments, but my preference is the Matlab > model. I don't > > think that the difference in native array storage order > matters much. > > It is more important to have the API at the plot method and > function > > level match the way people think. > > > > Eric |
|
From: Darren D. <dd...@co...> - 2006-07-12 20:37:51
|
On Wednesday 12 July 2006 16:16, Mark Bakker wrote: > I am following up on the discussion of passing a single 2D array to plot. > Wouldn't it make more sense that, in Python array style, > if you give it a single N x K argument you plot rows against the first row? That's not the behavior I would have expected. I would have expected each row to be plotted as a funtion of the column index, just like plot([1,2,3,4]) is done now, but with each row in a different color. I would like plot([1,2,3,4], array([[1,2,3,4],[2,3,4,5]])) to plot two lines as a function of the single x-list, and I would like plot(array([[1,2,3,4],[2,3,4,5]]), array([[1,2,3,4],[2,3,4,5]])) to take the next obvious step. I *think* matlab does this, but its been so long since I used it... Darren |
|
From: Eric F. <ef...@ha...> - 2006-07-12 22:34:28
|
Mark Bakker wrote: > > On the same token, it would be really nice if contour, pcolor and image > take as an x and y argument not only a matrix but just a 1D row. This > should be really easy and would be very useful. contour already does this, and I agree that pcolor and pcolormesh should. pcolor* is a little more complicated than contour because the X and Y dimensions are ideally larger by 1 than the corresponding Z dimensions, but don't have to be. image does not take x,y arguments at all, by design. > > In fact, if more people want it I can submit a patch for the latter one, OK. I suggest a function that can be used for both pcolor and pcolormesh. (Some day the two should be consolidated, but there is a pcolormesh bug with alpha != 1, so we can't do it yet.) Eric |
|
From: Eric F. <ef...@ha...> - 2006-07-12 23:19:58
|
Darren Dale wrote: > On Wednesday 12 July 2006 16:16, Mark Bakker wrote: > >>I am following up on the discussion of passing a single 2D array to plot. >>Wouldn't it make more sense that, in Python array style, >>if you give it a single N x K argument you plot rows against the first row? > > > That's not the behavior I would have expected. I would have expected each row > to be plotted as a funtion of the column index, just like plot([1,2,3,4]) is > done now, but with each row in a different color. I would like > plot([1,2,3,4], array([[1,2,3,4],[2,3,4,5]])) to plot two lines as a function > of the single x-list, and I would like plot(array([[1,2,3,4],[2,3,4,5]]), > array([[1,2,3,4],[2,3,4,5]])) to take the next obvious step. I *think* matlab > does this, but its been so long since I used it... I was afraid someone would bring up these possibilities... One of the problems with fancy argument handling is that there are many ways it can be done, so we have to decide on the behavior we want; and inevitably this will surprise (and probably irritate) some people just as it pleases others. (Other problems include complex code, complex documentation, and runtime overhead. For interactive use, however, fancy argument handling may be worth the trouble.) We are going to have some tradeoffs among matlab compatibility, internal consistency, and adherence to the underlying data storage model. Here is what Matlab does (and in one respect it is not what I thought I remembered): 1) Given a single NxK matrix, it plots each column against the row index. 2) Given a vector and an NxK, it plots each column against the vector. 3) Given an NxK and a vector, it plots the vector against each column. 4) Given an NxK and an NxK it plots each column from the second against the corresponding column of the first. I think this is a good model: fairly simple, consistent, intuitive, and covers a good range of real-life situations. It differs from what I thought I remembered, and from what I think Stefan requested, in that, given an Nx2, it does not plot the second column against the first. That behavior, however, does not generalize nicely to NxK for any K!=2, so I now think we should choose either one or the other. A virtue of Stefan's Nx2 proposal is that it is consistent with the changes I made to elsewhere so that paths can be specified as Nx2 arrays; this, in turn, was consistent with the original specification as sequences of (x,y) tuples. But plot has never used sequences of (x,y) tuples, so the argument for the Nx2 form is weaker here. I don't know whether the reason Matlab chooses the columns as the data vectors is because of the Fortran storage order Matlab uses, or whether there is some other reason. Personally I am very comfortable with it, perhaps simply because of my Matlab experience. I think part of it is that columns in a table seem more natural as data vectors than rows, however; tables are usually oriented so that columns (fields) are different variables, and the row index is the sample number, or time, or a spatial coordinate. To summarize, the options seem to be: 1) Leave plot argument parsing alone. 2) Accept an Nx2 array in place of a pair of arguments containing x and y. 3) Implement the Matlab model. 4) Implement the Matlab model, but taking rows instead of columns in an X or Y array that is 2-D. I am open to arguments, but my preference is the Matlab model. I don't think that the difference in native array storage order matters much. It is more important to have the API at the plot method and function level match the way people think. Eric |
|
From: Darren D. <dd...@co...> - 2006-07-13 02:01:34
|
On Wednesday 12 July 2006 7:19 pm, you wrote: > Darren Dale wrote: > > On Wednesday 12 July 2006 16:16, Mark Bakker wrote: > >>I am following up on the discussion of passing a single 2D array to plo= t. > >>Wouldn't it make more sense that, in Python array style, > >>if you give it a single N x K argument you plot rows against the first > >> row? > > > > That's not the behavior I would have expected. I would have expected ea= ch > > row to be plotted as a funtion of the column index, just like > > plot([1,2,3,4]) is done now, but with each row in a different color. I > > would like > > plot([1,2,3,4], array([[1,2,3,4],[2,3,4,5]])) to plot two lines as a > > function of the single x-list, and I would like=20 > > plot(array([[1,2,3,4],[2,3,4,5]]), array([[1,2,3,4],[2,3,4,5]])) to take > > the next obvious step. I *think* matlab does this, but its been so long > > since I used it... > > I was afraid someone would bring up these possibilities... Let me temper what I said. *If* a change was considered, what I described=20 seems to be the most intuitive behavior. > We are going to have some tradeoffs among matlab compatibility, internal > consistency, and adherence to the underlying data storage model. agreed > Here is what Matlab does (and in one respect it is not what I thought I > remembered): > > 1) Given a single NxK matrix, it plots each column against the row index. > > 2) Given a vector and an NxK, it plots each column against the vector. > > 3) Given an NxK and a vector, it plots the vector against each column. > > 4) Given an NxK and an NxK it plots each column from the second against > the corresponding column of the first. > > I think this is a good model: fairly simple, consistent, intuitive, and > covers a good range of real-life situations. =A0It differs from what I > thought I remembered, and from what I think Stefan requested, in that, > given an Nx2, it does not plot the second column against the first. > That behavior, however, does not generalize nicely to NxK for any K!=3D2, > so I now think we should choose either one or the other. =A0 A virtue of > Stefan's Nx2 proposal is that it is consistent with the changes I made > to elsewhere so that paths can be specified as Nx2 arrays; this, in > turn, was consistent with the original specification as sequences of > (x,y) tuples. =A0But plot has never used sequences of (x,y) tuples, so the > argument for the Nx2 form is weaker here. > > I don't know whether the reason Matlab chooses the columns as the data > vectors is because of the Fortran storage order Matlab uses, or whether > there is some other reason.=20 I believe this is the reason. > Personally I am very comfortable with it,=20 > perhaps simply because of my Matlab experience. =A0I think part of it is > that columns in a table seem more natural as data vectors than rows, > however; tables are usually oriented so that columns (fields) are > different variables, and the row index is the sample number, or time, or > a spatial coordinate. > > To summarize, the options seem to be: > > 1) Leave plot argument parsing alone. > 2) Accept an Nx2 array in place of a pair of arguments containing x and y. > > 3) Implement the Matlab model. > 4) Implement the Matlab model, but taking rows instead of columns in an > X or Y array that is 2-D. > > I am open to arguments, but my preference is the Matlab model. =A0I don't > think that the difference in native array storage order matters much. > It is more important to have the API at the plot method and function > level match the way people think. I would probably use 4, but not 3. I don't like the sound of 2. But that's= =20 just my opinion.=20 Darren |
|
From: Alan G I. <ai...@am...> - 2006-07-13 09:36:58
|
On Wed, 12 Jul 2006, Eric Firing apparently wrote: > 3) Implement the Matlab model. +1 Cheers, Alan Isaac PS This is fairly close to the (more constrained) GAUSS model. |
|
From: Stefan v. d. W. <st...@su...> - 2006-07-13 09:47:34
|
On Wed, Jul 12, 2006 at 01:19:41PM -1000, Eric Firing wrote: > To summarize, the options seem to be: >=20 > 1) Leave plot argument parsing alone. > 2) Accept an Nx2 array in place of a pair of arguments containing x and= y. >=20 > 3) Implement the Matlab model. > 4) Implement the Matlab model, but taking rows instead of columns in an= =20 > X or Y array that is 2-D. >=20 > I am open to arguments, but my preference is the Matlab model. I don't= =20 > think that the difference in native array storage order matters much.=20 > It is more important to have the API at the plot method and function=20 > level match the way people think. I wasn't aware of the matlab model when I made the suggestion -- havn't used it for such a long time! Option (3) looks good for consistency: for one argument, always plot agains row index, for two arguments, plot columns of x to columns of y, using broadcasting if necessary (i.e. if either x or y is a vector). Regards St=E9fan |