I've been collecting data from experiments and dumping them into .txt files and I decided to try and write a quick script to plot them with matplotlib. The plotting works fine, but I do not know how to label the plot based on the file name.
from numpy import *
from pylab import *
from matplotlib import rc
import sys
import os
rc('text',usetex=True)
rc('font',**{'family':'serif','serif':['Computer Modern']})
os.chdir(".")
for files in os.listdir("."):
if files.endswith(".txt"):
f = open(files,'r')
temp = []
for l in f:
temp.append(float(l))
plot(temp,labels=files)
hold(True)
legend(loc='lower left')
hold(False)
# Save the figure in a separate file
savefig('test.png')
# Draw the plot to the screen
show()
The problem seems to be with plot(temp,lables=files). If I put lables=files I get the error TypeError: There is no line property "labels". If I try and put labels='files', all the plots are labelled files which is useless. Does anyone know how to assign a lable to a plot based on a variable?
from foo import *. Just do not.