python - How to plot data from multiple two column text files with legends in Matplotlib? -
how open multiple text files different directories , plot them on single graph legends?
this relatively simple if use pylab (included matplotlib) instead of matplotlib directly. start off list of filenames , legend names, [ ('name of file 1', 'label 1'), ('name of file 2', 'label 2'), ...]. can use following:
import pylab datalist = [ ( pylab.loadtxt(filename), label ) filename, label in list_of_files ] data, label in datalist: pylab.plot( data[:,0], data[:,1], label=label ) pylab.legend() pylab.title("title of plot") pylab.xlabel("x axis label") pylab.ylabel("y axis label")
you might want add fmt='o' plot command, in order change line points. default, matplotlib pylab plots onto same figure without clearing it, can run plot command multiple times.
Comments
Post a Comment