【问题标题】:I've printed temperature values in one column in a file but want to graph temperature by row我在文件的一列中打印了温度值,但想逐行绘制温度图
【发布时间】:2015-10-26 01:42:32
【问题描述】:

我希望 x 轴是温度值所在的行,y 轴是实际值。我该怎么做呢?我将文件中的值打印到一列中。

【问题讨论】:

  • 你想要一个直方图吗? matplotlib.org/1.2.1/examples/pylab_examples/…
  • 不,我正在制作线图。我必须将温度导出到一个看起来像 900.227416583 803.500551551 712.488023688 629.361934539 555.650926429 492.179610726 439.093140606 的文件,并希望将每个值绘制成图表中的哪一行
  • 建立在@Hugh, plt.plot( row, temp)
  • @TylerDavis 该行包含什么(x 轴)?既然y轴就是x轴的行数?

标签: python graphing


【解决方案1】:
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()

给了

【讨论】:

  • 您导入的文件是什么样的?
  • @Tyler:每行包含一个浮点数的文本文件
  • 非常感谢,我计算了一根杆上任意点的温度,该杆的一端或两端随着时间的推移被加热,随着温度的扩散,无法将其绘制成图表,所以你是救生员。
猜你喜欢
  • 1970-01-01
  • 2016-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-25
  • 1970-01-01
相关资源
最近更新 更多