[Tutor] (no subject)

Evert Rol evert.rol at gmail.com
Sun Feb 12 11:59:57 CET 2012


  Hi,

Tip: use a meaningful subject line; attracts more/better attention and makes it easier to trace your email in the archives.

Continued at the bottom.

> import numpy as np
> import matplotlib.pyplot as plt
> E=[81.97400737666324, 322.0939978589591, 694.5766491226185]
> V0=1000
> a=0.1
> def V(x):
>    if x > -a and x < a:
>        return 0
>    return V0
> 
> V=np.vectorize(V)
> #psi=np.vectorize(psi)
> x= np.linspace(-1.5*a,1.5*a,100)
> 
> plt.plot(x,V(x))
> plt.xlim(-5*a,5*a)
> plt.ylim(-.001*V0,1.01*V0)
> for m in E:
>    x1=np.linspace(-a,+a,100)
>    #y=m
>    #plt.xlim(-5*a,5*a)
>    #plt.axhline(m)
>    #y=np.vectorize(y)
>    plt.plot(x1,m)
>    #plt.show()
>    print m
> 
> 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\uy.py in <module>()
>     23     #plt.axhline(m)
> 
>     24     #y=np.vectorize(y)
> 
> ---> 25     plt.plot(x1,m)
>     26     #plt.show()
> 
>     27     print m
> 
> 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

Read the error message: *same (first) dimension*

Then search where in your program the exception occurred:
C:\Users\as\uy.py in <module>()
    23     #plt.axhline(m)

    24     #y=np.vectorize(y)

---> 25     plt.plot(x1,m)
    26     #plt.show()

    27     print m

So, x1 and m don't have the same first dimension.
Try printing x1 and m before this statement (not after, like you did for m); just as a debug line.
Then see if you can figure out why m isn't what probably you want it to be.

Good luck,

  Evert



> 
> 
> Question:
> then how to plot those specific component of E within the square well omly?
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list