Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.
Close
From: surfcast23 <surfcast23@gm...>  20110824 20:48:32

I am fairly new to programing and have a question regarding matplotlib. I wrote a python script that reads in data from the outfile of another program then prints out the data from one column. f = open( 'myfile.txt','r') for line in f: if line != ' ': line = line.strip() # Strips end of line character columns = line.split() # Splits into coloumn mass = columns[8] # Column which contains mass values print(mass) What I now need to do is have matplotlib take the values printed in 'mass' and plot number versus mean mass. I have read the documents on the matplotlib website, but they don't really address how to get data from a script(or I just did not see it) If anyone can point me to some documentation that explains how I do this it would be really appreciated. Thanks in advance  View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32328822.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: gary ruben <gruben@bi...>  20110825 00:22:32

As you show it, mass will be a string, so you'll need to convert it to a float first, then add it to a list. You can then manipulate the values in the list to compute your mean, or whatever, which matplotlib can use as input to its plot() function or whichever type of plot you're after. Alternatively, since the Python numpy module is made for manipulating data like this, it can probably read your data in a single function call and easily compute the things you want. However, if you are really that new to programming, you may struggle, so I'd suggest reading first going to scipy.org and reading up on numpy. When you understand the basics of numpy, matplotlib's documentation should make a lot more sense. Gary On Thu, Aug 25, 2011 at 6:48 AM, surfcast23 <surfcast23@...> wrote: > > I am fairly new to programing and have a question regarding matplotlib. I > wrote a python script that reads in data from the outfile of another program > then prints out the data from one column. > > f = open( 'myfile.txt','r') > for line in f: > if line != ' ': > line = line.strip() # Strips end of line character > columns = line.split() # Splits into coloumn > mass = columns[8] # Column which contains mass values > print(mass) > > What I now need to do is have matplotlib take the values printed in 'mass' > and plot number versus mean mass. I have read the documents on the > matplotlib website, but they don't really address how to get data from a > script(or I just did not see it) If anyone can point me to some > documentation that explains how I do this it would be really appreciated. > Thanks in advance > >  > View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32328822.html > Sent from the matplotlib  users mailing list archive at Nabble.com. > > >  > EMC VNX: the world's simplest storage, starting under $10K > The only unified storage solution that offers unified management > Up to 160% more powerful than alternatives and 25% more efficient. > Guaranteed. http://p.sf.net/sfu/emcvnxdev2dev > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > 
From: surfcast23 <surfcast23@gm...>  20110825 00:38:15

Thank you Gary. I will definitely read the numpy doucs Gary Ruben2 wrote: > > As you show it, mass will be a string, so you'll need to convert it to > a float first, then add it to a list. You can then manipulate the > values in the list to compute your mean, or whatever, which matplotlib > can use as input to its plot() function or whichever type of plot > you're after. Alternatively, since the Python numpy module is made for > manipulating data like this, it can probably read your data in a > single function call and easily compute the things you want. However, > if you are really that new to programming, you may struggle, so I'd > suggest reading first going to scipy.org and reading up on numpy. When > you understand the basics of numpy, matplotlib's documentation should > make a lot more sense. > > Gary > > On Thu, Aug 25, 2011 at 6:48 AM, surfcast23 <surfcast23@...> wrote: >> >> I am fairly new to programing and have a question regarding matplotlib. I >> wrote a python script that reads in data from the outfile of another >> program >> then prints out the data from one column. >> >> f = open( 'myfile.txt','r') >> for line in f: >> if line != ' ': >> line = line.strip() # Strips end of line character >> columns = line.split() # Splits into coloumn >> mass = columns[8] # Column which contains mass values >> print(mass) >> >> What I now need to do is have matplotlib take the values printed in >> 'mass' >> and plot number versus mean mass. I have read the documents on the >> matplotlib website, but they don't really address how to get data from a >> script(or I just did not see it) If anyone can point me to some >> documentation that explains how I do this it would be really appreciated. >> Thanks in advance >> >>  >> View this message in context: >> http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32328822.html >> Sent from the matplotlib  users mailing list archive at Nabble.com. >> >> >>  >> EMC VNX: the world's simplest storage, starting under $10K >> The only unified storage solution that offers unified management >> Up to 160% more powerful than alternatives and 25% more efficient. >> Guaranteed. http://p.sf.net/sfu/emcvnxdev2dev >> _______________________________________________ >> Matplotlibusers mailing list >> Matplotlibusers@... >> https://lists.sourceforge.net/lists/listinfo/matplotlibusers >> > >  > EMC VNX: the world's simplest storage, starting under $10K > The only unified storage solution that offers unified management > Up to 160% more powerful than alternatives and 25% more efficient. > Guaranteed. http://p.sf.net/sfu/emcvnxdev2dev > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > >  View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32330761.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: mdekauwe <mdekauwe@gm...>  20110825 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], 'ro') 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/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32331474.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: surfcast23 <surfcast23@gm...>  20110825 18:16:03

Hi Martin, Thank for the relpy. What I have is a script that reads the data from a large file then prints out the values listed in a particular column. What I now need to do is have the information in that column plotted as the number of rows vs. the mean value of all of the rows. What I have so far is import matplotlib.pyplot as plt masses = [] f = open( 'myfile.txt','r') f.readline() for line in f: if line != ' ': line = line.strip() # Strips end of line character columns = line.split() # Splits into coloumn mass = columns[8] # Column which contains mass values mass = float(mass) masses.append(mass) print(mass) plt.plot() plt.show I am thinking I can do something like 'y runs fron 0 to n where n == len(masses) ' x = 'mass_avg = sum(masses)/len(masses)' Problem is I don' tknow how to have matplotlib do it with out giving me an error about dimentions. I would also like to do this with out having to write and read from another file. I alos need to to be able to work on files with ddifering numbers of rows. Thanks mdekauwe wrote: > > 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], 'ro') > 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/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32336570.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: mdekauwe <mdekauwe@gm...>  20110825 23:46:36

Hi, Well the first bit about wanting a specific column and the last bit about not wanting to print all the data in and read it back, you get that from the example I gave you. If you paste what I wrote for you line by line it should become clearer for you, additionally it avoids you have to write your own parsing code. As far as your plotting goes, unless you actually post what you are entering in the script (exactly as you have it), then it is impossible to say. For example plt.plot() plt.show there is no way that is all you have? if it is, then of course you will get a fail as you are asking matplotlib to plot but are not providing it with any data to plot! Perhaps I am being particularly dense but "What I now need to do is have the information in that column plotted as the number of rows vs. the mean value of all of the rows." means nothing to me. Sorry. What do you want on the X and Y... do you mean you want to plot your individual column (8 i think you called it) against the mean of all the other rows? If so I would expect you would have a dimensions issue Martin  View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32338485.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: surfcast23 <surfcast23@gm...>  20110826 01:35:07

Hi, I apologize if my explanation was less than clear. What I have is data in a column that runs from row 1 to row 1268. In each each row there is a number. For example 1 3 5 6 7 8 9 so I want the y axis to run from 1 to 7 ( the number of rows) and the x axis to be the average of the values in this case 5.57. I am having problems with setting up the yaxis as well as the dimension problem you addressed. Is there a way I could have every value on the x axis the same? Say for the above example have the x and y axis be 7 6 5 4 3 2 1 5.75 5.57 5.57 5.75 5.57 5.57 5.75 Which would be the number of rows vs the average value of the data in the rows and then plot that? Thanks again Khary mdekauwe wrote: > > Hi, > > Well the first bit about wanting a specific column and the last bit about > not wanting to print all the data in and read it back, you get that from > the example I gave you. If you paste what I wrote for you line by line it > should become clearer for you, additionally it avoids you have to write > your own parsing code. > > As far as your plotting goes, unless you actually post what you are > entering in the script (exactly as you have it), then it is impossible to > say. For example > > plt.plot() > plt.show > > there is no way that is all you have? if it is, then of course you will > get a fail as you are asking matplotlib to plot but are not providing it > with any data to plot! > > Perhaps I am being particularly dense but "What I now need to do is have > the information in that column plotted as the number of rows vs. the mean > value of all of the rows." means nothing to me. Sorry. What do you want on > the X and Y... do you mean you want to plot your individual column (8 i > think you called it) against the mean of all the other rows? If so I would > expect you would have a dimensions issue > > Martin > > >  View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32338750.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: mdekauwe <mdekauwe@gm...>  20110826 01:50:57

still don't quite get this, so you want for each column the average? and you want to plot each of these averages? So a bar graph? with 8 bars? surfcast23 wrote: > > Hi, > > I apologize if my explanation was less than clear. What I have is data > in a column that runs from row 1 to row 1268. In each each row there is a > number. For example > > 1 > 3 > 5 > 6 > 7 > 8 > 9 > > so I want the y axis to run from 1 to 7 ( the number of rows) and the x > axis to be the average of the values in this case 5.57. I am having > problems with setting up the yaxis as well as the dimension problem you > addressed. > > Is there a way I could have every value on the x axis the same? Say for > the above example have the x and y axis be > > 7 > 6 > 5 > 4 > 3 > 2 > 1 > 5.75 5.57 5.57 5.75 5.57 5.57 5.75 > > Which would be the number of rows vs the average value of the data in the > rows and then plot that? > > Thanks again > > Khary > > > > mdekauwe wrote: >> >> Hi, >> >> Well the first bit about wanting a specific column and the last bit about >> not wanting to print all the data in and read it back, you get that from >> the example I gave you. If you paste what I wrote for you line by line it >> should become clearer for you, additionally it avoids you have to write >> your own parsing code. >> >> As far as your plotting goes, unless you actually post what you are >> entering in the script (exactly as you have it), then it is impossible to >> say. For example >> >> plt.plot() >> plt.show >> >> there is no way that is all you have? if it is, then of course you will >> get a fail as you are asking matplotlib to plot but are not providing it >> with any data to plot! >> >> Perhaps I am being particularly dense but "What I now need to do is have >> the information in that column plotted as the number of rows vs. the mean >> value of all of the rows." means nothing to me. Sorry. What do you want >> on the X and Y... do you mean you want to plot your individual column (8 >> i think you called it) against the mean of all the other rows? If so I >> would expect you would have a dimensions issue >> >> Martin >> >> >> > >  View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32338805.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: surfcast23 <surfcast23@gm...>  20110826 02:01:45

Hi, there is only one column. so I want a plot of y and x. With y taking values running from 0 to n or 7 in my example and x as the average of the values that are contained in the rows in my example it was 5.57. mdekauwe wrote: > > still don't quite get this, so you want for each column the average? and > you want to plot each of these averages? So a bar graph? with 8 bars? > > > > surfcast23 wrote: >> >> Hi, >> >> I apologize if my explanation was less than clear. What I have is data >> in a column that runs from row 1 to row 1268. In each each row there is a >> number. For example >> >> 1 >> 3 >> 5 >> 6 >> 7 >> 8 >> 9 >> >> so I want the y axis to run from 1 to 7 ( the number of rows) and the x >> axis to be the average of the values in this case 5.57. I am having >> problems with setting up the yaxis as well as the dimension problem >> you addressed. >> >> Is there a way I could have every value on the x axis the same? Say for >> the above example have the x and y axis be >> >> 7 >> 6 >> 5 >> 4 >> 3 >> 2 >> 1 >> 5.75 5.57 5.57 5.75 5.57 5.57 5.75 >> >> Which would be the number of rows vs the average value of the data in >> the rows and then plot that? >> >> Thanks again >> >> Khary >> >> >> >> mdekauwe wrote: >>> >>> Hi, >>> >>> Well the first bit about wanting a specific column and the last bit >>> about not wanting to print all the data in and read it back, you get >>> that from the example I gave you. If you paste what I wrote for you line >>> by line it should become clearer for you, additionally it avoids you >>> have to write your own parsing code. >>> >>> As far as your plotting goes, unless you actually post what you are >>> entering in the script (exactly as you have it), then it is impossible >>> to say. For example >>> >>> plt.plot() >>> plt.show >>> >>> there is no way that is all you have? if it is, then of course you will >>> get a fail as you are asking matplotlib to plot but are not providing it >>> with any data to plot! >>> >>> Perhaps I am being particularly dense but "What I now need to do is have >>> the information in that column plotted as the number of rows vs. the >>> mean value of all of the rows." means nothing to me. Sorry. What do you >>> want on the X and Y... do you mean you want to plot your individual >>> column (8 i think you called it) against the mean of all the other rows? >>> If so I would expect you would have a dimensions issue >>> >>> Martin >>> >>> >>> >> >> > >  View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32338836.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: mdekauwe <mdekauwe@gm...>  20110826 02:22:46

Perhaps someone else can help as I feel I am being particularly dense. for i in xrange(numcols): ax.plot([np.mean(mass[:,7]) for i in xrange(numcols)], np.arange(numcols), label=i) This gives you what I think you said, but really don't think this is what you mean as it seems a strange thing to want to do. sorry i couldn't be of more help surfcast23 wrote: > > Hi, > > there is only one column. so I want a plot of y and x. With y taking > values running from 0 to n or 7 in my example and x as the average of the > values that are contained in the rows in my example it was 5.57. > > > > mdekauwe wrote: >> >> still don't quite get this, so you want for each column the average? and >> you want to plot each of these averages? So a bar graph? with 8 bars? >> >> >> >> surfcast23 wrote: >>> >>> Hi, >>> >>> I apologize if my explanation was less than clear. What I have is >>> data in a column that runs from row 1 to row 1268. In each each row >>> there is a number. For example >>> >>> 1 >>> 3 >>> 5 >>> 6 >>> 7 >>> 8 >>> 9 >>> >>> so I want the y axis to run from 1 to 7 ( the number of rows) and the x >>> axis to be the average of the values in this case 5.57. I am having >>> problems with setting up the yaxis as well as the dimension problem >>> you addressed. >>> >>> Is there a way I could have every value on the x axis the same? Say for >>> the above example have the x and y axis be >>> >>> 7 >>> 6 >>> 5 >>> 4 >>> 3 >>> 2 >>> 1 >>> 5.75 5.57 5.57 5.75 5.57 5.57 5.75 >>> >>> Which would be the number of rows vs the average value of the data in >>> the rows and then plot that? >>> >>> Thanks again >>> >>> Khary >>> >>> >>> >>> mdekauwe wrote: >>>> >>>> Hi, >>>> >>>> Well the first bit about wanting a specific column and the last bit >>>> about not wanting to print all the data in and read it back, you get >>>> that from the example I gave you. If you paste what I wrote for you >>>> line by line it should become clearer for you, additionally it avoids >>>> you have to write your own parsing code. >>>> >>>> As far as your plotting goes, unless you actually post what you are >>>> entering in the script (exactly as you have it), then it is impossible >>>> to say. For example >>>> >>>> plt.plot() >>>> plt.show >>>> >>>> there is no way that is all you have? if it is, then of course you will >>>> get a fail as you are asking matplotlib to plot but are not providing >>>> it with any data to plot! >>>> >>>> Perhaps I am being particularly dense but "What I now need to do is >>>> have the information in that column plotted as the number of rows vs. >>>> the mean value of all of the rows." means nothing to me. Sorry. What do >>>> you want on the X and Y... do you mean you want to plot your individual >>>> column (8 i think you called it) against the mean of all the other >>>> rows? If so I would expect you would have a dimensions issue >>>> >>>> Martin >>>> >>>> >>>> >>> >>> >> >> > >  View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32338899.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: surfcast23 <surfcast23@gm...>  20110826 02:27:05

No problem thanks for helping mdekauwe wrote: > > Perhaps someone else can help as I feel I am being particularly dense. > > for i in xrange(numcols): > ax.plot([np.mean(mass[:,7]) for i in xrange(numcols)], > np.arange(numcols), label=i) > > This gives you what I think you said, but really don't think this is what > you mean as it seems a strange thing to want to do. > > sorry i couldn't be of more help > > > surfcast23 wrote: >> >> Hi, >> >> there is only one column. so I want a plot of y and x. With y taking >> values running from 0 to n or 7 in my example and x as the average of >> the values that are contained in the rows in my example it was 5.57. >> >> >> >> mdekauwe wrote: >>> >>> still don't quite get this, so you want for each column the average? and >>> you want to plot each of these averages? So a bar graph? with 8 bars? >>> >>> >>> >>> surfcast23 wrote: >>>> >>>> Hi, >>>> >>>> I apologize if my explanation was less than clear. What I have is >>>> data in a column that runs from row 1 to row 1268. In each each row >>>> there is a number. For example >>>> >>>> 1 >>>> 3 >>>> 5 >>>> 6 >>>> 7 >>>> 8 >>>> 9 >>>> >>>> so I want the y axis to run from 1 to 7 ( the number of rows) and the >>>> x axis to be the average of the values in this case 5.57. I am having >>>> problems with setting up the yaxis as well as the dimension problem >>>> you addressed. >>>> >>>> Is there a way I could have every value on the x axis the same? Say >>>> for the above example have the x and y axis be >>>> >>>> 7 >>>> 6 >>>> 5 >>>> 4 >>>> 3 >>>> 2 >>>> 1 >>>> 5.75 5.57 5.57 5.75 5.57 5.57 5.75 >>>> >>>> Which would be the number of rows vs the average value of the data in >>>> the rows and then plot that? >>>> >>>> Thanks again >>>> >>>> Khary >>>> >>>> >>>> >>>> mdekauwe wrote: >>>>> >>>>> Hi, >>>>> >>>>> Well the first bit about wanting a specific column and the last bit >>>>> about not wanting to print all the data in and read it back, you get >>>>> that from the example I gave you. If you paste what I wrote for you >>>>> line by line it should become clearer for you, additionally it avoids >>>>> you have to write your own parsing code. >>>>> >>>>> As far as your plotting goes, unless you actually post what you are >>>>> entering in the script (exactly as you have it), then it is impossible >>>>> to say. For example >>>>> >>>>> plt.plot() >>>>> plt.show >>>>> >>>>> there is no way that is all you have? if it is, then of course you >>>>> will get a fail as you are asking matplotlib to plot but are not >>>>> providing it with any data to plot! >>>>> >>>>> Perhaps I am being particularly dense but "What I now need to do is >>>>> have the information in that column plotted as the number of rows vs. >>>>> the mean value of all of the rows." means nothing to me. Sorry. What >>>>> do you want on the X and Y... do you mean you want to plot your >>>>> individual column (8 i think you called it) against the mean of all >>>>> the other rows? If so I would expect you would have a dimensions issue >>>>> >>>>> Martin >>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > >  View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32338914.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: C M <cmpython@gm...>  20110826 02:29:42

On Thu, Aug 25, 2011 at 10:01 PM, surfcast23 <surfcast23@...> wrote: > > Hi, > > there is only one column. so I want a plot of y and x. With y taking > values running from 0 to n or 7 in my example and x as the average of the > values that are contained in the rows in my example it was 5.57. It seems to me that, as described, you want a plot that in which all the bars are the same height (or width if it is a sideways bar chart), in this case, 5.57. That makes no sense. What information is this plot is intended to provide the viewer? 
From: surfcast23 <surfcast23@gm...>  20110826 04:06:41

Sorry everyone I totally missed something very important. What I need to do is first bin the masses(which I don't know how to do). Chelonian wrote: > > On Thu, Aug 25, 2011 at 10:01 PM, surfcast23 <surfcast23@...> wrote: >> >> Hi, >> >> there is only one column. so I want a plot of y and x. With y taking >> values running from 0 to n or 7 in my example and x as the average of >> the >> values that are contained in the rows in my example it was 5.57. > > It seems to me that, as described, you want a plot that in which all > the bars are the same height (or width if it is a sideways bar chart), > in this case, 5.57. That makes no sense. > > What information is this plot is intended to provide the viewer? > >  > EMC VNX: the world's simplest storage, starting under $10K > The only unified storage solution that offers unified management > Up to 160% more powerful than alternatives and 25% more efficient. > Guaranteed. http://p.sf.net/sfu/emcvnxdev2dev > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > >  View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32339216.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: mdekauwe <mdekauwe@gm...>  20110829 13:59:34

Can you describe what you want to do? So you now want a histogram? surfcast23 wrote: > > Sorry everyone I totally missed something very important. What I need to > do is first bin the masses(which I don't know how to do). > > Chelonian wrote: >> >> On Thu, Aug 25, 2011 at 10:01 PM, surfcast23 <surfcast23@...> >> wrote: >>> >>> Hi, >>> >>> there is only one column. so I want a plot of y and x. With y taking >>> values running from 0 to n or 7 in my example and x as the average of >>> the >>> values that are contained in the rows in my example it was 5.57. >> >> It seems to me that, as described, you want a plot that in which all >> the bars are the same height (or width if it is a sideways bar chart), >> in this case, 5.57. That makes no sense. >> >> What information is this plot is intended to provide the viewer? >> >>  >> EMC VNX: the world's simplest storage, starting under $10K >> The only unified storage solution that offers unified management >> Up to 160% more powerful than alternatives and 25% more efficient. >> Guaranteed. http://p.sf.net/sfu/emcvnxdev2dev >> _______________________________________________ >> Matplotlibusers mailing list >> Matplotlibusers@... >> https://lists.sourceforge.net/lists/listinfo/matplotlibusers >> >> > >  View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32357095.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: surfcast23 <surfcast23@gm...>  20110903 18:11:04

Hi Martin, Sorry I am just responding. I have been busy getting ready for the semester. What I need to do is first sort the values contained in the column and assign them to bins. I then have to plot the number of bins by the mean value in each bin. mdekauwe wrote: > > Can you describe what you want to do? So you now want a histogram? > > > surfcast23 wrote: >> >> Sorry everyone I totally missed something very important. What I need to >> do is first bin the masses(which I don't know how to do). >> >> Chelonian wrote: >>> >>> On Thu, Aug 25, 2011 at 10:01 PM, surfcast23 <surfcast23@...> >>> wrote: >>>> >>>> Hi, >>>> >>>> there is only one column. so I want a plot of y and x. With y taking >>>> values running from 0 to n or 7 in my example and x as the average of >>>> the >>>> values that are contained in the rows in my example it was 5.57. >>> >>> It seems to me that, as described, you want a plot that in which all >>> the bars are the same height (or width if it is a sideways bar chart), >>> in this case, 5.57. That makes no sense. >>> >>> What information is this plot is intended to provide the viewer? >>> >>>  >>> EMC VNX: the world's simplest storage, starting under $10K >>> The only unified storage solution that offers unified management >>> Up to 160% more powerful than alternatives and 25% more efficient. >>> Guaranteed. http://p.sf.net/sfu/emcvnxdev2dev >>> _______________________________________________ >>> Matplotlibusers mailing list >>> Matplotlibusers@... >>> https://lists.sourceforge.net/lists/listinfo/matplotlibusers >>> >>> >> >> > >  View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32393079.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: mdekauwe <mdekauwe@gm...>  20110903 23:32:40

So you do want a histogram then? I assume you have all of this sorted then, the histogram function is very good. Cheers, Martin  View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32394062.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: C M <cmpython@gm...>  20110904 03:58:56

On Sat, Sep 3, 2011 at 7:32 PM, mdekauwe <mdekauwe@...> wrote: > > So you do want a histogram then? I assume you have all of this sorted then, > the histogram function is very good. I don't think he's describing a histogram, because he is not plotting frequency of observations on the y axis, but data values (means of each bin). I think what surfcast23 wants is just a bar graph. So, surfcast23, I'd suggest you break it down into your two steps. First, how will you average your values by bin? You can probably figure that out by writing it out on paper in pseudocode and then just putting it in Python. Then you'll have a list of means, and you will pass that to the bar function in matplotlib, something like: from pylab import * ax = subplot(111) x = arange(4) your_list_of_means = [4,5,7,11] #computed earlier bar(x, your_list_of_means) xticks( x + 0.5, ('Bin1', 'Bin2', 'Bin3', 'Bin4') ) show() Che 
From: surfcast23 <surfcast23@gm...>  20110906 17:01:24

Thanks for everyone responses and help Che, You are correct on what I have to do. The problem is that I have a data set with ~1250 so I cant' do the sorting or finding the mean by hand. I guess what I need to to is to write a script that will sort the values, bin them, and keep track of the number of values in each bin. Then find the mean value in each bin. Then the scrip has to take the number of values in each bin and plot that versus the mean of each bin. I apologies for the lack of clarity in my earlier posts. It was unclear to me what exactly had to be done until this weekend. Chelonian wrote: > > On Sat, Sep 3, 2011 at 7:32 PM, mdekauwe <mdekauwe@...> wrote: >> >> So you do want a histogram then? I assume you have all of this sorted >> then, >> the histogram function is very good. > > I don't think he's describing a histogram, because he is not plotting > frequency of observations on the y axis, but data values (means of > each bin). I think what surfcast23 wants is just a bar graph. > > So, surfcast23, I'd suggest you break it down into your two steps. > First, how will you average your values by bin? You can probably > figure that out by writing it out on paper in pseudocode and then > just putting it in Python. Then you'll have a list of means, and you > will pass that to the bar function in matplotlib, something like: > > from pylab import * > ax = subplot(111) > x = arange(4) > your_list_of_means = [4,5,7,11] #computed earlier > bar(x, your_list_of_means) > xticks( x + 0.5, ('Bin1', 'Bin2', 'Bin3', 'Bin4') ) > show() > > Che > >  > Special Offer  Download ArcSight Logger for FREE! > Finally, a worldclass log management solution at an even better > pricefree! And you'll get a free "Love Thy Logs" tshirt when you > download Logger. Secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsisghtdev2dev > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > >  View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32409886.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: Benjamin Root <ben.root@ou...>  20110906 17:08:28
Attachments:
Message as HTML

On Tue, Sep 6, 2011 at 12:01 PM, surfcast23 <surfcast23@...> wrote: > > Thanks for everyone responses and help > > Che, > > You are correct on what I have to do. The problem is that I have a data > set > with ~1250 so I cant' do the sorting or finding the mean by hand. I guess > what I need to to is to write a script that will sort the values, bin them, > and keep track of the number of values in each bin. Then find the mean > value > in each bin. Then the scrip has to take the number of values in each bin > and > plot that versus the mean of each bin. I apologies for the lack of clarity > in my earlier posts. It was unclear to me what exactly had to be done until > this weekend. > > > I think you really need to read up on the NumPy documentation. There are functions that will do this for you. NumPy can load/save data, sort them, bin them, find means and standard deviations, etc... You don't need to reinvent the wheel. Plus, you keep on talking about having a script for each part. While it is great that you like modularity, Python does support the use of functions, and I would encourage you to use them. Cheers, Ben Root 
From: C M <cmpython@gm...>  20110906 17:19:40

>> The problem is that I have a data set >> with ~1250 so I cant' do the sorting or finding the mean by hand. That's not a problemthat's programming! Even if you had a data set with five items you should be in the mind set that "by hand" is an 18th century approach. This will drive further progress in your coding abilities. > I think you really need to read up on the NumPy documentation. There are > functions that will do this for you. NumPy can load/save data, sort them, > bin them, find means and standard deviations, etc... You don't need to > reinvent the wheel. Ben, that's a good idea. The only thing here, though, is that probably the OP would be well served in practicing Python basics and learning how to think up procedures, write them down, and then put them into Python code. Reinventing the wheel, *at least to learn* could really be useful here. I've also found that sometimes it is easier to just reinvent a wheel than learn a library's API, at least to get started. Considering his task requires mostly just creating lists based on conditionals and then doing some 5th grade math, he might want to try it himself before he uses NumPy. But of course he can get there either way. Che 
From: surfcast23 <surfcast23@gm...>  20110906 18:52:00

Benjamin Root2 wrote: > > On Tue, Sep 6, 2011 at 12:01 PM, surfcast23 <surfcast23@...> wrote: > >> >> Thanks for everyone responses and help >> >> Che, >> >> You are correct on what I have to do. The problem is that I have a data >> set >> with ~1250 so I cant' do the sorting or finding the mean by hand. I guess >> what I need to to is to write a script that will sort the values, bin >> them, >> and keep track of the number of values in each bin. Then find the mean >> value >> in each bin. Then the scrip has to take the number of values in each bin >> and >> plot that versus the mean of each bin. I apologies for the lack of >> clarity >> in my earlier posts. It was unclear to me what exactly had to be done >> until >> this weekend. >> >> >> > I think you really need to read up on the NumPy documentation. There are > functions that will do this for you. NumPy can load/save data, sort them, > bin them, find means and standard deviations, etc... You don't need to > reinvent the wheel. > > Plus, you keep on talking about having a script for each part. While it > is > great that you like modularity, Python does support the use of functions, > and I would encourage you to use them. > > Cheers, > Ben Root > >  > Special Offer  Download ArcSight Logger for FREE! > Finally, a worldclass log management solution at an even better > pricefree! And you'll get a free "Love Thy Logs" tshirt when you > download Logger. Secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsisghtdev2dev > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > > Hi Ben, I will read up the numpy docs when I get some time. I am only writing one script that will do everything sorry if I gave the impression of having multiple scripts.  View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32410694.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: Ryan Nelson <rnelsonchem@gm...>  20110826 01:28:03
Attachments:
Message as HTML

If I understand your question correctly, I may have a solution to your problem. First of all, the statement below, when converted to Python code, will generate an array of numbers the same length of your masses list. > 'y runs fron 0 to n where n == len(masses) ' However, this statement will give you a single number: > x = 'mass_avg = sum(masses)/len(masses)' You will not be able to plot these two objects because of the different sizes. If you are asking about a 'running' or cumulative mean, then you may want to use the cumulative sum function from Numpy (cumsum). To convert this into a cumulative average, you can do a simple division. Below is a modification to your script that incorporates this averaging technique. (I don't know why you want to print everything. Surely you can't see all of the data as the file gets processed. It is also a very slow operation... I'll just ignore those parts.) import numpy as np import matplotlib.pyplot as plt f = open('myfile.txt') f.next() # You want to skip the first line, I guess. mass = [] for line in f: # This will skip the lines that are spaces. if line.isspace(): continue # The strip function is unnecessary. The defalut for the split function takes care of that. columns = line.split() # Don't call the float function every time. It's a waste. mass.append( columns[8] ) # Here we can convert the list of strings into an array of floats with the dtype keyword. mass = np.array( mass, dtype='float') # Here's the cumulative average steps. mass_sum = np.cumsum(mass) mass_average = mass_sum/ np.arange(1, len(mass_sum) + 1) # If you only plot one array or list of values, they are assumed to be the y values. # The x values in that case are the indices of the y value array. plt.plot(mass_average) plt.show() Ryan > Message: 5 > Date: Thu, 25 Aug 2011 11:15:57 0700 (PDT) > From: surfcast23 <surfcast23@...> > Subject: Re: [Matplotlibusers] How do you Plot data generated by a > python script? > To: matplotlibusers@... > MessageID: <32336570.post@...> > ContentType: text/plain; charset=usascii > > > Hi Martin, > > Thank for the relpy. What I have is a script that reads the data from > a large file then prints out the values listed in a particular column. What > I now need to do is have the information in that column plotted as the > number of rows vs. the mean value of all of the rows. What I have so far is > > import matplotlib.pyplot as plt > > masses = [] > > f = open( 'myfile.txt','r') > f.readline() > for line in f: > if line != ' ': > line = line.strip() # Strips end of line character > columns = line.split() # Splits into coloumn > mass = columns[8] # Column which contains mass values > mass = float(mass) > masses.append(mass) > print(mass) > > plt.plot() > plt.show > > > I am thinking I can do something like > > 'y runs fron 0 to n where n == len(masses) ' > x = 'mass_avg = sum(masses)/len(masses)' > > Problem is I don' tknow how to have matplotlib do it with out giving me an > error about dimentions. I would also like to do this with out having to > write and read from another file. I alos need to to be able to work on > files > with ddifering numbers of rows. > > Thanks > > > > > > mdekauwe wrote: > > > > 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], 'ro') > > 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/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32336570.html > Sent from the matplotlib  users mailing list archive at Nabble.com. > > 
From: surfcast23 <surfcast23@gm...>  20110826 01:44:37

Hi Ryan, I think your solution will work thank you!! I did get an error though it is " f.next() # You want to skip the first line, I guess. AttributeError: '_io.TextIOWrapper' object has no attribute 'next' " thank you Khary rcnelson wrote: > > If I understand your question correctly, I may have a solution to your > problem. First of all, the statement below, when converted to Python > code, will generate an array of numbers the same length of your masses > list. >> 'y runs fron 0 to n where n == len(masses) ' > However, this statement will give you a single number: >> x = 'mass_avg = sum(masses)/len(masses)' > You will not be able to plot these two objects because of the different > sizes. If you are asking about a 'running' or cumulative mean, then you > may > want to use the cumulative sum function from Numpy (cumsum). To convert > this > into a cumulative average, you can do a simple division. > > Below is a modification to your script that incorporates this averaging > technique. (I don't know why you want to print everything. Surely you > can't > see all of the data as the file gets processed. It is also a very slow > operation... I'll just ignore those parts.) > > import numpy as np > import matplotlib.pyplot as plt > f = open('myfile.txt') > f.next() # You want to skip the first line, I guess. > mass = [] > for line in f: > # This will skip the lines that are spaces. > if line.isspace(): continue > # The strip function is unnecessary. The defalut for the split > function > takes care of that. > columns = line.split() > # Don't call the float function every time. It's a waste. > mass.append( columns[8] ) > # Here we can convert the list of strings into an array of floats with the > dtype keyword. > mass = np.array( mass, dtype='float') > # Here's the cumulative average steps. > mass_sum = np.cumsum(mass) > mass_average = mass_sum/ np.arange(1, len(mass_sum) + 1) > # If you only plot one array or list of values, they are assumed to be the > y > values. > # The x values in that case are the indices of the y value array. > plt.plot(mass_average) > plt.show() > > > Ryan > > >> Message: 5 >> Date: Thu, 25 Aug 2011 11:15:57 0700 (PDT) >> From: surfcast23 <surfcast23@...> >> Subject: Re: [Matplotlibusers] How do you Plot data generated by a >> python script? >> To: matplotlibusers@... >> MessageID: <32336570.post@...> >> ContentType: text/plain; charset=usascii >> >> >> Hi Martin, >> >> Thank for the relpy. What I have is a script that reads the data >> from >> a large file then prints out the values listed in a particular column. >> What >> I now need to do is have the information in that column plotted as the >> number of rows vs. the mean value of all of the rows. What I have so far >> is >> >> import matplotlib.pyplot as plt >> >> masses = [] >> >> f = open( 'myfile.txt','r') >> f.readline() >> for line in f: >> if line != ' ': >> line = line.strip() # Strips end of line character >> columns = line.split() # Splits into coloumn >> mass = columns[8] # Column which contains mass values >> mass = float(mass) >> masses.append(mass) >> print(mass) >> >> plt.plot() >> plt.show >> >> >> I am thinking I can do something like >> >> 'y runs fron 0 to n where n == len(masses) ' >> x = 'mass_avg = sum(masses)/len(masses)' >> >> Problem is I don' tknow how to have matplotlib do it with out giving me >> an >> error about dimentions. I would also like to do this with out having to >> write and read from another file. I alos need to to be able to work on >> files >> with ddifering numbers of rows. >> >> Thanks >> >> >> >> >> >> mdekauwe wrote: >> > >> > 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], 'ro') >> > 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/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32336570.html >> Sent from the matplotlib  users mailing list archive at Nabble.com. >> >> > >  > EMC VNX: the world's simplest storage, starting under $10K > The only unified storage solution that offers unified management > Up to 160% more powerful than alternatives and 25% more efficient. > Guaranteed. http://p.sf.net/sfu/emcvnxdev2dev > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > >  View this message in context: http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32338782.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: Jonny Milliken <thinkingmansopium@gm...>  20110826 13:42:12
Attachments:
Message as HTML

You could always just save it as a list and then plot from there? The average calculation is a bit redundant though, I'm sure theres a better way of doing it import pylab import numpy >>f = open( 'myfile.txt','r') mass_store =[] >>for line in f: >>if line != ' ': >> line = line.strip() # Strips end of line character >> columns = line.split() # Splits into coloumn >> mass = columns[8] # Column which contains mass values >> print(mass) mass_store.append(mass) >> pylab.plot(range(len(mass_store)),mass_store) pylab.plot(range(len(mass_store)),[numpy.mean(mass_store)]*len(mass_store)) pylab.show() (or pylab.savefig('location.png') to save ) Jonny On 24 August 2011 19:46, surfcast23 <surfcast23@...> wrote: > > I am fairly new to programing and have a question regarding matplotlib. I > wrote a python script that reads in data from the outfile of another > program > then prints out the data from one column. > > f = open( 'myfile.txt','r') > for line in f: > if line != ' ': > line = line.strip() # Strips end of line character > columns = line.split() # Splits into coloumn > mass = columns[8] # Column which contains mass values > print(mass) > > What I now need to do is have matplotlib take the values printed in 'mass' > and plot the sum of the values over the average of the values. I have read > the documents on the matplotlib website, but they are don't really address > how to get data from a script(or I just did not see it). If anyone can > point > me to some documentation that explains how I do this it would be really > appreciated. > Thanks in advance > >  > View this message in context: > http://old.nabble.com/HowdoyouPlotdatageneratedbyapythonscripttp32328822p32328822.html > Sent from the matplotlib  users mailing list archive at Nabble.com. > > > >  > EMC VNX: the world's simplest storage, starting under $10K > The only unified storage solution that offers unified management > Up to 160% more powerful than alternatives and 25% more efficient. > Guaranteed. http://p.sf.net/sfu/emcvnxdev2dev > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > 
From: Neal Becker <ndbecker2@gm...>  20110904 14:40:41

surfcast23 wrote: > > I am fairly new to programing and have a question regarding matplotlib. I > wrote a python script that reads in data from the outfile of another program > then prints out the data from one column. > > f = open( 'myfile.txt','r') > for line in f: > if line != ' ': > line = line.strip() # Strips end of line character > columns = line.split() # Splits into coloumn > mass = columns[8] # Column which contains mass values > print(mass) > > What I now need to do is have matplotlib take the values printed in 'mass' > and plot number versus mean mass. I have read the documents on the > matplotlib website, but they don't really address how to get data from a > script(or I just did not see it) If anyone can point me to some > documentation that explains how I do this it would be really appreciated. > Thanks in advance > What I always do, is in my script I pickle the parameters used to run the script, and the results. Usually I save a pair of dicts, one of the parameters, and one of the results. Then to plot, just unpickle them and have at it. 