【发布时间】:2011-03-09 19:30:29
【问题描述】:
我正在尝试绘制从对 numpy 数组的各个列求和获得的数组值。 在 Win XP、Python 2.5、matplotlib-1.0.1、numpy-1.5.1、PIL-1.1.7 上工作 代码如下:
import Image
import numpy as np
import matplotlib.pyplot as plt
im = Image.open("tish.pnm")
im = im.convert("1") # convert necessary to import into numpy array
pixels = im.getdata()
n = len(pixels)
data = np.reshape(pixels, im.size)
sums = {}
#sum the range of column values
for i in range(0, data.shape[0]):
sums[i] = data[:,i].sum()
#this is where I can't get pyplot to work
plt.plot(sums) # this crashes with a "ValueError: need more than 0 values to unpack"
plt.plot(i,sums) #crashes with the same error
当我执行“打印总和”时 我得到如下数据:
{0: 705330, 1: 667845, 2: 693855, 3: 663000, 4: 699210, 5: 660705, 6: 686970, 7: 662490, 8: 697425, 9: 660450, 10: 688500, 11: 663510,...2913:65295}
我做错了什么?
【问题讨论】:
标签: python numpy matplotlib