Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98747
| From | Laura Creighton <lac@openend.se> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Matplotlib error: Value Error: x and y must have same first dimension |
| Date | 2015-11-13 16:43 +0100 |
| Message-ID | <mailman.292.1447429441.16136.python-list@python.org> (permalink) |
| References | <40964e99-cd31-4daa-8f5f-069b09816b3d@googlegroups.com> <201511130834.tAD8YNra005833@fido.openend.se> <CAHVvXxQVs7O8K7cCiya7=yovwxHAdPoPZh6CQV4hsMEFroBYLA@mail.gmail.com> |
In a message of Fri, 13 Nov 2015 14:04:01 +0000, Oscar Benjamin writes: >On 13 November 2015 at 08:34, Laura Creighton <lac@openend.se> wrote: >> In a message of Thu, 12 Nov 2015 17:54:28 -0800, Abhishek writes: >>>I am trying to run some Python code for the last few hours. How can I achieve the effect of "dot divide" from Matlab, in the following code? I am having trouble working with list comprehension and numpy arrays and getting the following error: >>> >>> Traceback (most recent call last): >>> File "Thurs.py", line 128, in <module> >>> plt.plot(np.array(range(1,N/2+2)), Splot[alpha][iii,val]/utot[iii,val],color=cmap(iii/50)) >>> >>> ValueError: x and y must have same first dimension >> >> Splot is a list. matplotlib wants 2 numpy arrays. You have to cast >> it with np.array() too. > >Actually the plot command is perfectly happy converting lists or lists >of lists etc. to arrays (by calling np.array internally) so you don't >need to convert any of your inputs. By the way: np.arange(1, N/2+2) >would be the usual way to create a numpy array that is a range. > >The error here comes because (after both arguments are converted to >arrays) they have incompatible sizes. In other words: > > len(range(1,N/2+2)) != len(Splot[alpha][iii,val]/utot[iii,val]) > >I'm not sure what the solution is as the code is too complex for me to >spend time trying to guess what it's trying to do. > >-- >Oscar I am sorry for the bad information. Thank you Oscar. Laura
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Matplotlib error: Value Error: x and y must have same first dimension Abhishek <abhishek.mallela@gmail.com> - 2015-11-12 17:54 -0800 Re: Matplotlib error: Value Error: x and y must have same first dimension Laura Creighton <lac@openend.se> - 2015-11-13 09:34 +0100 Re: Matplotlib error: Value Error: x and y must have same first dimension Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-11-13 14:04 +0000 Re: Matplotlib error: Value Error: x and y must have same first dimension Laura Creighton <lac@openend.se> - 2015-11-13 16:43 +0100 Re: Matplotlib error: Value Error: x and y must have same first dimension Abhishek Mallela <abhishek.mallela@gmail.com> - 2015-11-13 11:44 -0600
csiph-web