Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo
Close
From: AG <computing.account@go...>  20100321 18:56:38

Hi List I cannot figure out how to satisfy this issue to resolve the ValueError: x and y must have same first dimension. This is the relevant code: [code] for i in range( 0, time + 1 ): outflow = constant * quantity quantityChange = inflow  outflow changeList.append( quantityChange ) print "%2d %9.2f %11.3f %11.3f %10.3f" % ( i, inflow, quantity, outflow, quantityChange ) quantity += quantityChange # Plot on graph x = np.arange( time ) y = np.arange( quantityChange ) plt.plot( x, y, label="rate of change" ) plt.ylabel( "Quantity" ) plt.xlabel( "Time" ) plt.show() [/code] I have picked up that neither a 'list' or an 'int' are iterable objects, but I am stymied by how I can successfully get the x and y axes to portray the data outputs. Also, what does that error message mean? That the starting point must be 0 or of the same object type? I haven't found a clear answer in the tutorial pages yet, but I will perservere. TIA AG 
From: Gökhan Sever <gokhansever@gm...>  20100321 19:04:38
Attachments:
Message as HTML

On Sun, Mar 21, 2010 at 1:57 PM, AG <computing.account@...>wrote: > Hi List > > I cannot figure out how to satisfy this issue to resolve the ValueError: > x and y must have same first dimension. > > > This is the relevant code: > [code] > > for i in range( 0, time + 1 ): > > outflow = constant * quantity > > quantityChange = inflow  outflow > > changeList.append( quantityChange ) > > print "%2d %9.2f %11.3f %11.3f %10.3f" % ( i, inflow, quantity, > outflow, quantityChange ) > > quantity += quantityChange > > > > # Plot on graph > > x = np.arange( time ) > y = np.arange( quantityChange ) > > plt.plot( x, y, label="rate of change" ) > plt.ylabel( "Quantity" ) > plt.xlabel( "Time" ) > plt.show() > > > [/code] > > I have picked up that neither a 'list' or an 'int' are iterable objects, > but I am stymied by how I can successfully get the x and y axes to > portray the data outputs. > > Also, what does that error message mean? That the starting point must > be 0 or of the same object type? I haven't found a clear answer in the > tutorial pages yet, but I will perservere. > > TIA > > AG > > > x and y must be in the same length otherwise you hit that error message. try simply to see the failure: plt.plot([1,2], [1,2,3]) Use len(x) or x.shape to see how many elements in the array and adjust your code to make x and y has the same length before plotting.  Gökhan 
From: AG <computing.account@go...>  20100321 19:29:47
Attachments:
Message as HTML

Gökhan Sever wrote: > > > On Sun, Mar 21, 2010 at 1:57 PM, AG <computing.account@... > <mailto:computing.account@...>> wrote: > > Hi List > > I cannot figure out how to satisfy this issue to resolve the > ValueError: > x and y must have same first dimension. > > > This is the relevant code: > [code] > > for i in range( 0, time + 1 ): > > outflow = constant * quantity > > quantityChange = inflow  outflow > > changeList.append( quantityChange ) > > print "%2d %9.2f %11.3f %11.3f %10.3f" % ( i, inflow, quantity, > outflow, quantityChange ) > > quantity += quantityChange > > > > # Plot on graph > > x = np.arange( time ) > y = np.arange( quantityChange ) > > plt.plot( x, y, label="rate of change" ) > plt.ylabel( "Quantity" ) > plt.xlabel( "Time" ) > plt.show() > > > [/code] > > I have picked up that neither a 'list' or an 'int' are iterable > objects, > but I am stymied by how I can successfully get the x and y axes to > portray the data outputs. > > Also, what does that error message mean? That the starting point > must > be 0 or of the same object type? I haven't found a clear answer > in the > tutorial pages yet, but I will perservere. > > TIA > > AG > > > > x and y must be in the same length otherwise you hit that error message. > > try simply to see the failure: > > plt.plot([1,2], [1,2,3]) > > Use len(x) or x.shape to see how many elements in the array and adjust > your code to make x and y has the same length before plotting. > > >  > Gökhan That was very helpful, thank you Gökhan. Having played around with it a bit, I think I've got it fixed. Thanks. AG 