当前位置: 代码迷 >> python >> 我已经在文件的一列中打印了温度值,但想按行绘制温度图
  详细解决方案

我已经在文件的一列中打印了温度值,但想按行绘制温度图

热度:25   发布时间:2023-06-16 10:19:37.0

我希望 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()

这使

  相关解决方案