1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 【Python】ValueError: x and y must have same first dimension but have shapes (5 ) and (4 )

【Python】ValueError: x and y must have same first dimension but have shapes (5 ) and (4 )

时间:2023-05-13 01:54:31

相关推荐

【Python】ValueError: x and y must have same first dimension  but have shapes (5 ) and (4 )

调用matplotlib作图的时候,输入的 x 和 y 的值数量不一致产生的。画图的 xy 的值必须在一个维度,就是 x 有几个数,y 就要有几个数。比如下面代码,我 x 输出 [2, 4, 6, 8, 10] 5个数,但是我 y 填写了4个数,所以就会报标题这个错误。

from matplotlib import pyplot as pltx = range(2,12,2)print(list(x))# 输出 [2, 4, 6, 8, 10]y = [10,12,33,17]plt.plot(x,y)plt.show()

如果我把 y 改成 :

y = [10,12,33,17,11]

这样就会出现如下图,这样系统就正常了,其他图也一样的,注意下就好了

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。