I'm trying to make a program that will create a descending series of plots based on given files containing an n*2 matrix of numerical values (they more or less share an x-axis, and they're close enough on the y-axis that they need to be manipulated to avoid overlap).
Right now, the way it works is to read in the files one at a time with fileinput, add a constant to the values in column two (arbitrary so long as the constant splits each plot; I do it by multiplying the number of files by two, and decrementing by two each plot so they get split), then add the manipulated values to two master lists (for x and y), which are plotted at the end by matplotlib.
I have it doing very close to exactly what I want, but it has some odd lines connecting the end of one file to the beginning of the next, and I'd like to know how to remove them.
Here's the relevant part of the code:
mpl.suptitle(spectitle, fontsize=16)
mpl.xlabel('wavelength (A)', fontsize=14)
mpl.ylabel('flux (erg s^-1 cm^-2)', fontsize=14)
with open(filelist) as infile:
allfiles = [line.rstrip('\n') for line in open(filelist)]
multiplier = len(allfiles)
multiplier *= 2
for line in fileinput.input(allfiles):
filename = fileinput.filename()
waveN, fluxN = np.loadtxt(filename, usecols=[0,1], unpack=True)
fluxCalc = np.array(fluxN)
fluxCalc += multiplier
multiplier -= 2 #decrease multiplier, causing next output specturm to be placed below the one just calculated
wavelenAll.extend(waveN)
fluxCalc.tolist()
fluxAll.extend(fluxCalc)
fileinput.nextfile()
mpl.plot(wavelenAll, fluxAll)
mpl.savefig('allspec.png')
mpl.show()
I can add an image of the output in a few hours. Thanks for any help in advance.