I would like to write a program that creates 100 masked plots from a spread of 100 text files. i.e. for fnum in range(1,100,1):
The text files are numbered xydata1.txt, xydata2.txt … until xydata100.txt.
How is this best done in Python?
Below is my plotting program, where (file number fnum) = 1,2,3…100.
fn = 'xydata'+fnum+'.txt'
y = loadtxt(fn,unpack=True,usecols=[0])
x = loadtxt(fn,unpack=True,usecols=[1])
n = ma.masked_where(gradient(y) < 0, y)
p = ma.masked_where(gradient(y) > 0, y)
pylab.plot(x,n,'r',x,p,'g')
pylab.savefig('data'+fnum+'.png')
pylab.show()
Assuming Python 2.7
You can also use masked arrays. But the only advantage of them is to avoid allocating new memory. If your plots are small enough, you don’t need them.
By the way there is no “best answer”.