Python ValueError:需要超过1个值才能解包如何修复它

Python ValueError:需要超过1个值才能解包如何修复它,python,numpy,matplotlib,plot,zip,Python,Numpy,Matplotlib,Plot,Zip,我试图用python(2.7)进行绘图,但我得到了一个ValueError:需要超过1个值才能解包 我的代码如下所示: x, y = zip(*list_with_data) xlocs = np.arange(len(x)) fig = plt.figure() ax = fig.gca() ax.bar(xlocs + 0.6, y) ax.set_xticks(xlocs + 1) ax.set_xticklabels(x) ax.set_xlim(0.0, xlocs.max() +

我试图用python(2.7)进行绘图,但我得到了一个ValueError:需要超过1个值才能解包

我的代码如下所示:

x, y = zip(*list_with_data) 
xlocs = np.arange(len(x))

fig = plt.figure()
ax = fig.gca()
ax.bar(xlocs + 0.6, y)
ax.set_xticks(xlocs + 1)
ax.set_xticklabels(x)
ax.set_xlim(0.0, xlocs.max() + 2)

plt.show()
我的

我希望x标签是文本包含的数字:

1,2,3,4,5,6

我想让我的y标签表示:它们在文本中包含了多少次

例如:

x: 1, y: 150
x: 2, y: 20

如何从我的数据集中打印此数据?

您正在压缩dict键的键,因此您只有一个值,因此出现解包错误:

In [12]: list_with_data = Counter("1 2 3 2 3 4 5 6")

In [13]: zip(*list_with_data)
Out[13]: [(' ', '1', '3', '2', '5', '4', '6')] 
如果要解压缩两个值,则需要两个值:

In [14]: x, y = zip(*list_with_data.items())  
In [15]: x
Out[15]: (' ', '1', '3', '2', '5', '4', '6')

In [16]: y
Out[16]: (7, 1, 2, 2, 1, 1, 1

什么是包含数据的列表?它是一个包含50k个字母的文本文件。我需要计算每个字母的数量来计算概率,然后我应该使用这个概率生成一个随机文本。我是在@Padraic Cunningham的帮助下完成的。但是谢谢大家。你们为什么一直破坏你们自己的帖子?因为这没用,这是错误的。@py.codan,为什么你们想把x标为字母,y标为频率?应该可以,所以另一种选择是
x,y=list\u with_data.keys(),list\u with_data.values()
In [14]: x, y = zip(*list_with_data.items())  
In [15]: x
Out[15]: (' ', '1', '3', '2', '5', '4', '6')

In [16]: y
Out[16]: (7, 1, 2, 2, 1, 1, 1