ValueError: x and y must have same first dimension

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.

···

On Sun, Mar 21, 2010 at 1:57 PM, AG <computing.account@…982…> 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:


> 
> 
> 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()
> 
> 
> 
> 
> 

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


Gökhan

Gökhan Sever 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:


> > 
> > 
> > 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()
> > 
> > 
> > 
> > 
> > 

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

···

On Sun, Mar 21, 2010 at 1:57 PM, AG <computing.account@…982…> > wrote: