## Re: [Matplotlib-users] How do you Plot data generated by a python script?

 Re: [Matplotlib-users] How do you Plot data generated by a python script? From: mdekauwe - 2011-08-25 04:46:20 ```I wasn't quite able to follow exactly what you wanted to do but maybe this will help. I am going to generate some "data" that I think sounds a bit like yours, write it to a file, clearly you already have this. Then I am going to read it back in and plot it, e.g. import matplotlib.pyplot as plt import numpy as np # Generate some data a little like yours, I think? # print it to a file, i.e. I am making your myfile.txt numrows = 100 numcols = 8 mass = np.random.normal(0, 1, (numrows * numcols)).reshape(numrows, numcols) f = open("myfile.txt", "w") for i in xrange(numrows): for j in xrange(numcols): print >>f, mass[i,j], print >> f f.close() # read the file back in mass = np.loadtxt("myfile.txt") # plot the 8th column fig = plt.figure() ax = fig.add_subplot(111) ax.plot(mass[:,7], 'r-o') ax.set_xlabel("Time") ax.set_ylabel("Mass") plt.show() I wasn't clear on the mean bit, but that is easy to do with numpy, e.g. mean_mass = np.mean(mass[:,8]) etc. Numpy et al is great for stuff like this. Hope that helps, Martin -- View this message in context: http://old.nabble.com/How-do-you-Plot-data-generated-by-a-python-script--tp32328822p32331474.html Sent from the matplotlib - users mailing list archive at Nabble.com. ```