ValueError: x and y must have same first dimension, but have shapes (1, 120) and (120,)

ValueError: x and y must have same first dimension, but have shapes (1, 120) and (120,)

报错代码如下:


import random
from matplotlib import pyplot  as  plt

x = [range(0, 120)]   #➀
y = [random.randint(20, 35) for item in range(120)]


plt.plot(x, y, color='green') #➁
plt.show()

因为是➁处 x 应该传入一个 rang类型,但是➀处是list类型, 将➀处的代码改为 x = range(0, 120) 即可

你可能感兴趣的:(python)