Message from discussion
pylab: ValueError: x and y must have same first dimension
Received: by 10.204.10.88 with SMTP id o24mr1653241bko.0.1346657775013;
Mon, 03 Sep 2012 00:36:15 -0700 (PDT)
X-BeenThere: nltk-users@googlegroups.com
Received: by 10.204.157.26 with SMTP id z26ls397927bkw.1.gmail; Mon, 03 Sep
2012 00:36:13 -0700 (PDT)
Received: by 10.204.130.7 with SMTP id q7mr1658521bks.2.1346657773690;
Mon, 03 Sep 2012 00:36:13 -0700 (PDT)
Received: by 10.204.130.7 with SMTP id q7mr1658520bks.2.1346657773673;
Mon, 03 Sep 2012 00:36:13 -0700 (PDT)
Return-Path: <peter.ljung...@heatherleaf.se>
Received: from mailgw13.surf-town.net (mail1.surf-town.net. [212.97.132.41])
by gmr-mx.google.com with ESMTP id j4si3026094bkj.3.2012.09.03.00.36.13;
Mon, 03 Sep 2012 00:36:13 -0700 (PDT)
Received-SPF: neutral (google.com: 212.97.132.41 is neither permitted nor denied by best guess record for domain of peter.ljung...@heatherleaf.se) client-ip=212.97.132.41;
Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.97.132.41 is neither permitted nor denied by best guess record for domain of peter.ljung...@heatherleaf.se) smtp.mail=peter.ljung...@heatherleaf.se
Received: by mailgw13.surf-town.net (Postfix, from userid 65534)
id 7981240190; Mon, 3 Sep 2012 09:36:13 +0200 (CEST)
Received: from localhost (localhost [127.0.0.1])
by mailgw13.surf-town.net (Postfix) with ESMTP id 04D8D40190
for <nltk-users@googlegroups.com>; Mon, 3 Sep 2012 09:36:13 +0200 (CEST)
X-Virus-Scanned: Debian amavisd-new at mailgw13.surf-town.net
X-Spam-Flag: NO
X-Spam-Score: -1.44
X-Spam-Level:
X-Spam-Status: No, score=-1.44 tagged_above=-999 required=7
tests=[ALL_TRUSTED=-1.44] autolearn=disabled
Received: from mailgw13.surf-town.net ([127.0.0.1])
by localhost (mailgw13.surf-town.net [127.0.0.1]) (amavisd-new, port 10024)
with LMTP id mT0+xUabBaeS for <nltk-users@googlegroups.com>;
Mon, 3 Sep 2012 09:36:10 +0200 (CEST)
Received: from [10.0.1.10] (dhcp2-022135.cs.chalmers.se [129.16.22.135])
by mailgw13.surf-town.net (Postfix) with ESMTPSA id 38AA8404CD
for <nltk-users@googlegroups.com>; Mon, 3 Sep 2012 09:36:10 +0200 (CEST)
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0 (Apple Message framework v1278)
Subject: Re: [nltk-users] pylab: ValueError: x and y must have same first dimension
From: =?iso-8859-1?Q?peter_ljungl=F6f?= <peter.ljung...@heatherleaf.se>
In-Reply-To: <e2bd9297-beeb-4a95-9e4b-52ac3ba4bc07@googlegroups.com>
Date: Mon, 3 Sep 2012 09:36:17 +0200
Content-Transfer-Encoding: quoted-printable
Message-Id: <06E4A457-CA87-464D-8863-2776D438F...@heatherleaf.se>
References: <e2bd9297-beeb-4a95-9e4b-52ac3ba4bc07@googlegroups.com>
To: nltk-users@googlegroups.com
X-Mailer: Apple Mail (2.1278)
Why do you use string quotes in the calls to y.extend and index.extend?
/Peter
22 aug 2012 kl. 06:10 skrev typetoken:
> I wrote the following codes to make a plot. However, it pops up =
ValueError: x and y must have same first dimension. Any tips for the =
following codes? thanks.
>=20
> >>> def zif(text):
> fdist =3D nltk.FreqDist(text)
> import pylab
> word =3D fdist.keys()
> x =3D []
> y =3D []
> index =3D []
> for i in range(0,len(set(text)),1):
> x.extend(word[i:i+1])
> y.extend('fdist[word[i:i+1]]')
> index.extend('i+1')
> pylab.plot(index, y,'b')
> pylab.title('zipf law')
> pylab.xlabel('word rank')
> pylab.ylabel('word frequency')
> pylab.show()
>=20
> =09
> >>> zif(text)
>=20
> Traceback (most recent call last):
> File "<pyshell#35>", line 1, in <module>
> zif(text)
> File "<pyshell#34>", line 12, in zif
> pylab.plot(index, y,'b')
> File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line =
2458, in plot
> ret =3D ax.plot(*args, **kwargs)
> File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 3848, =
in plot
> for line in self._get_lines(*args, **kwargs):
> File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 323, =
in _grab_next_args
> for seg in self._plot_args(remaining, kwargs):
> File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 300, =
in _plot_args
> x, y =3D self._xy_from_xy(x, y)
> File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 240, =
in _xy_from_xy
> raise ValueError("x and y must have same first dimension")
> ValueError: x and y must have same first dimension=20
>=20
> Thanks indeed.
>=20
> --=20
> You received this message because you are subscribed to the Google =
Groups "nltk-users" group.
> To view this discussion on the web visit =
https://groups.google.com/d/msg/nltk-users/-/UYjFHCSpuC0J.
> To post to this group, send email to nltk-users@googlegroups.com.
> To unsubscribe from this group, send email to =
nltk-users+unsubscribe@googlegroups.com.
> For more options, visit this group at =
http://groups.google.com/group/nltk-users?hl=3Den.