[Tutor] ploting of a square well
Debashish Saha
silideba at gmail.com
Sun Feb 5 18:07:42 CET 2012
---------- Forwarded message ----------
From: Debashish Saha <silideba at gmail.com>
Date: Sun, Feb 5, 2012 at 7:08 PM
Subject: ploting of a square well
To: tutor at python.org
from pylab import *
x=linspace(1,1000,10000)
a,b = 10,20
def v(x):
i=5;v0=2
for n in range(1,1+i):
if x>(n-1)*(a+b) and x<a+(n-1)*(a+b):
return 0
elif x>a+(n-1)*(a+b) and x<(n)*(a+b) :
return v0
#v=vectorize(v)
plot(x,v)
show()
Error:
ValueError Traceback (most recent call last)
C:\Python27\lib\site-packages\IPython\utils\py3compat.pyc in
execfile(fname, glob, loc)
166 else:
167 filename = fname
--> 168 exec compile(scripttext, filename, 'exec') in glob, loc
169 else:
170 def execfile(fname, *where):
C:\Users\as\klj.py in <module>()
10 return v0
11 #v=vectorize(v)
---> 12 plot(x,v)
13 show()
C:\Python27\lib\site-packages\matplotlib\pyplot.pyc in plot(*args, **kwargs)
2456 ax.hold(hold)
2457 try:
-> 2458 ret = ax.plot(*args, **kwargs)
2459 draw_if_interactive()
2460 finally:
C:\Python27\lib\site-packages\matplotlib\axes.pyc in plot(self, *args, **kwargs)
3846 lines = []
3847
-> 3848 for line in self._get_lines(*args, **kwargs):
3849 self.add_line(line)
3850 lines.append(line)
C:\Python27\lib\site-packages\matplotlib\axes.pyc in
_grab_next_args(self, *args, **kwargs)
321 return
322 if len(remaining) <= 3:
--> 323 for seg in self._plot_args(remaining, kwargs):
324 yield seg
325 return
C:\Python27\lib\site-packages\matplotlib\axes.pyc in _plot_args(self,
tup, kwargs)
298 x = np.arange(y.shape[0], dtype=float)
299
--> 300 x, y = self._xy_from_xy(x, y)
301
302 if self.command == 'plot':
C:\Python27\lib\site-packages\matplotlib\axes.pyc in _xy_from_xy(self, x, y)
238 y = np.atleast_1d(y)
239 if x.shape[0] != y.shape[0]:
--> 240 raise ValueError("x and y must have same first dimension")
241 if x.ndim > 2 or y.ndim > 2:
242 raise ValueError("x and y can be no greater than 2-D")
ValueError: x and y must have same first dimension
Question:
what is to be edited?
More information about the Tutor
mailing list