I want the x-axis to be what row the temperature value is in and the y-axis to be the actual value. How do I do this? I printed values to a file into one column.
Asked
Active
Viewed 32 times
-1
-
Do you want a histogram? http://matplotlib.org/1.2.1/examples/pylab_examples/histogram_demo.html – Julien Oct 26 '15 at 01:47
-
No I'm making a line plot. I have to export the temperatures to a file that look like 900.227416583 803.500551551 712.488023688 629.361934539 555.650926429 492.179610726 439.093140606 and want to graph each value by which row it's in in a line graph – Tyler Davis Oct 26 '15 at 01:49
-
1See http://matplotlib.org/users/pyplot_tutorial.html – Hugh Bothwell Oct 26 '15 at 01:51
-
Building off @Hugh, `plt.plot( row, temp)` – Julien Oct 26 '15 at 01:52
-
@TylerDavis what does the row contain (x-axis)? Since the y-axis is the x-axis the number of the row? – Leb Oct 26 '15 at 01:55
-
each row has a value. it looks like one column of numbers. I want to plot the top number by 0, the second number down as 1 etc. – Tyler Davis Oct 26 '15 at 02:00
1 Answers
0
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()
which gives

Hugh Bothwell
- 55,315
- 8
- 84
- 99
-
-
@Tyler: a text file containing one floating-point number per line – Hugh Bothwell Oct 26 '15 at 02:09
-
Thank you so much I calculated the temperature of arbitrary points along a rod heated at one or both ends over time as the temperature spreads and couldn't get it to graph so you are a life saver. – Tyler Davis Oct 26 '15 at 02:21