From: Zoe C. <zoe...@iw...> - 2005-09-06 16:03:59
|
Dear gnuplot-py users, I am trying to plot a series of files with python and gnuplot named sequentially as: temp/spectra1.dat temp/spectra2.dat temp/spectra3.dat ..... and so on I am generating each of these files in a loop and try to open them and store each file in a postscript file as: > for i in range(1,detectors): > data = open('temp/spectra'+str(i)+'.dat','r') > g.plot(data) > g.hardcopy('gp_test'+str(i)+'.ps', enhanced=0, color=1) > g.q This doens't seem to work, what is my mistake? Thank you very much for any help, Zoe -- ----------------------------------------------------------------- | Zoe Cournia, Dipl.-Chem. Phone: | | University of Heidelberg +49 6221 548808 (office) | | IWR - Computational Biophysics +49 179 4840634 (mobile) | | Im Neuenheimer Feld 368 +49 6221 346050 (home) | | D-69120 Heidelberg Fax: +49 6221 548868 | | | | email: zoe...@iw... | | http://spider.iwr.uni-heidelberg.de/~cournia/ | ----------------------------------------------------------------- |
From: Michael H. <mh...@al...> - 2005-09-06 20:17:03
|
Zoe Cournia wrote: > I am trying to plot a series of files with python and gnuplot named > sequentially as: > > temp/spectra1.dat > temp/spectra2.dat > temp/spectra3.dat ..... and so on > > I am generating each of these files in a loop and try to open them and > store each file in a postscript file as: > >> for i in range(1,detectors): >> data = open('temp/spectra'+str(i)+'.dat','r') >> g.plot(data) >> g.hardcopy('gp_test'+str(i)+'.ps', enhanced=0, color=1) >> g.q To plot a file, you don't open the file using Python but rather pass the plot method a Gnuplot.File object, like g.plot(Gnuplot.File('temp/spectra'+str(i)+'.dat')) With that change, I think it should work. (Of course, you could alternatively open the file using python, read the data into a python array, then plot the array, but that approach doesn't have any advantages unless you want to process the data before plotting it.) Michael |
From: Zoe C. <zoe...@iw...> - 2005-09-07 13:56:26
|
Dear Michael, Thank you for the answer. Indeed it works like this now. The structure of the files however, require that the command in gnuplot is: plot 'temp/spectra9.dat' u 1:2 otherwise the file cannot be plotted (bad data in line 0) so is there a way to incorporate the 'u 1:2' command in the g.plot command that you siggest? g.plot(Gnuplot.File('temp/spectra'+str(i)+'.dat')) thank you Zoe Michael Haggerty wrote: >Zoe Cournia wrote: > > >>I am trying to plot a series of files with python and gnuplot named >>sequentially as: >> >>temp/spectra1.dat >>temp/spectra2.dat >>temp/spectra3.dat ..... and so on >> >>I am generating each of these files in a loop and try to open them and >>store each file in a postscript file as: >> >> >> >>>for i in range(1,detectors): >>> data = open('temp/spectra'+str(i)+'.dat','r') >>> g.plot(data) >>> g.hardcopy('gp_test'+str(i)+'.ps', enhanced=0, color=1) >>> g.q >>> >>> > >To plot a file, you don't open the file using Python but rather pass the >plot method a Gnuplot.File object, like > > g.plot(Gnuplot.File('temp/spectra'+str(i)+'.dat')) > >With that change, I think it should work. > >(Of course, you could alternatively open the file using python, read the >data into a python array, then plot the array, but that approach doesn't >have any advantages unless you want to process the data before plotting it.) > >Michael > > >------------------------------------------------------- >SF.Net email is Sponsored by the Better Software Conference & EXPO >September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices >Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA >Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf >_______________________________________________ >Gnuplot-py-users mailing list >Gnu...@li... >https://lists.sourceforge.net/lists/listinfo/gnuplot-py-users > > > -- ----------------------------------------------------------------- | Zoe Cournia, Dipl.-Chem. Phone: | | University of Heidelberg +49 6221 548808 (office) | | IWR - Computational Biophysics +49 179 4840634 (mobile) | | Im Neuenheimer Feld 368 +49 6221 346050 (home) | | D-69120 Heidelberg Fax: +49 6221 548868 | | | | email: zoe...@iw... | | http://spider.iwr.uni-heidelberg.de/~cournia/ | ----------------------------------------------------------------- |
From: Michael H. <mh...@al...> - 2005-09-07 18:52:41
|
Zoe Cournia wrote: > Thank you for the answer. Indeed it works like this now. > The structure of the files however, require that the command in gnuplot is: > > plot 'temp/spectra9.dat' u 1:2 > > otherwise the file cannot be plotted (bad data in line 0) > so is there a way to incorporate the 'u 1:2' command in the g.plot > command that you siggest? > > g.plot(Gnuplot.File('temp/spectra'+str(i)+'.dat')) g.plot(Gnuplot.File('temp/spectra'+str(i)+'.dat', using=1:2)) I recommend looking in demo.py for lots of examples like this. Michael |