Python Matplotlib如何在每周一次的intervale中绘制折线图

时间:2016-02-10 13:12:23

标签: python numpy matplotlib

我正在一个需要绘制数据和折线图的项目中工作。问题是我没有X值我只有Y值 这是我要绘制的值的列表:

     testlist =['278264', '322823', '287298', '295212', '299174', '277271',  '352717', '583802', '1167864', '1622965', '1759879', '1779014', '174791']

我喜欢的结果就是这个截图enter image description here

但是我的代码我正在考虑这个结果enter image description here

我尝试了以下代码,但我遇到了错误:ValueError:x和y必须具有相同的第一个维度

testlist =['278264', '322823', '287298', '295212', '299174', '277271', '352717', '583802', '1167864', '1622965', '1759879', '1779014', '174791']
last = len(testlist)
for i in range (0,last):
    intValue= int(testlist[i])
    testlist[i]=intValue

x = [1,7,13,19,25,31]
y = testlist


plt.plot(x,y)

关于如何解决这个问题的任何想法? 谢谢

1 个答案:

答案 0 :(得分:1)

显然你得到一个错误,因为你有13个y值和7个x值。 通常点(x,y)对吗?所以你需要len(x) == len(y)

你在哪里获得了你想要的截图?你能检索一下它的数据吗?正如你所说,你没有x轴,但你必须得到它,否则x轴将任意,有道理不是吗?

此致 保罗