我在文件的一列中打印了温度值,但想按行绘制温度图
I've printed temperature values in one column in a file but want to graph temperature by row
我希望x轴是温度值所在的行,y轴是实际值。我该怎么做呢?我将文件中的值打印到一列中。
import matplotlib.pyplot as plt
# get data
with open("data.txt") as myfile:
temps = [float(row) for row in myfile]
# generate line numbers
num_rows = len(temps)
rownums = list(range(num_rows)) # starting at 0!
# plot
plt.plot(rownums, temps)
plt.show()
这给出了
我希望x轴是温度值所在的行,y轴是实际值。我该怎么做呢?我将文件中的值打印到一列中。
import matplotlib.pyplot as plt
# get data
with open("data.txt") as myfile:
temps = [float(row) for row in myfile]
# generate line numbers
num_rows = len(temps)
rownums = list(range(num_rows)) # starting at 0!
# plot
plt.plot(rownums, temps)
plt.show()
这给出了