繁体   English   中英

在matplotlib中绘制折线图

[英]Plotting line graphs in matplotlib

我正在尝试绘制连接的线图。 如果我对下面的代码进行更改,则该图无法显示。

到目前为止,我的情节充满了未连接的点。

如何生成连接点的折线图?

x = np.zeros(sheet_1.max_row)
y = np.zeros(sheet_1.max_row)

print (sheet_1.max_row)
print (sheet_1.max_column)

f = open("Bad_Data_Points_CD25.txt", "w")

for i in range(0, 10): #change to 1000
    for j in range(0, 289): # change to 289

        x[i] = sheet_1.cell(row=i + 1, column=j + 1).value #J + 1 changed to J
        print x[i]
        plt.plot(i, x[i],'go-', label='Values')



plt.grid(True)

plt.title("ABCD")
plt.ylabel("ABCD")
plt.ylim(0,0.15)
plt.xlabel("ABCD")
plt.xlim(0, 10)

plt.show()

您的循环结构使您每个数据点发出一个plot()调用。 但是,如果您一次绘制整个序列,则只会看到连接的线。

我在下面做了3处更改:

  • 由于您已选择为j每个不同值覆盖x并重用x的方式,因此我交换了两个循环的嵌套顺序

  • 我没有缩进plot命令,因此它是j循环的一部分,而不是i循环的一部分

  • 我更改了plot参数以一次绘制整个x

     for j in range(0, 289): # change to 289 for i in range(0, 10): x[i] = sheet_1.cell(row=i + 1, column=j + 1).value #J + 1 changed to J print x[i] plt.plot(x, 'go-', label='Values from column %d' % (j+1)) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM