【发布时间】:2021-03-06 21:57:05
【问题描述】:
我正在尝试使用 pyplot.plot() 绘制存储在列表中的值,但它正在将存储在列表中的值绘制在图上的索引处。
我尝试使用 numpy.array() 将列表类型转换为数组,但遇到了同样的问题。
我还检查以确保使用 for 循环正确读取值。
import matplotlib.pyplot as plt
import numpy as np
readin = open('datapoints.txt', 'r')
xpoints = []
ypoints = []
i = 0
for line in readin:
line = line.split(' ')
xpoints.append(line[0])
ypoints.append(line[1])
i += 1
print(i)
plt.ylim([-5, 20])
plt.xlim([-5, 20])
plt.plot(xpoints, ypoints)
plt.show()
【问题讨论】:
-
可能是因为您将 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] 绘制为 y 值。你试过
plt.plot(xpoints, ypoints)吗? -
是的,我改变它来尝试调试。当我这样做时,y 点也会发生同样的问题。我会尝试附上一张图片。
标签: python matplotlib