[Tutor] HELP: Creating animation from multiple plots
Dear All, I am a newbie to Python but have a fair know how of other languages i.e C etc. I want to run an astrophysical simulation in Python. All I have to do it to generate a set of 'plots' depending on a varying parameter and then stitch them up. 1) Is it possible to automatically generate different data files( say in the orders of 1000) with different names depending on a parameter? 2) Is it possible to plot the data sets right from Python itself and save the plots in different jpeg files to stitched upon later on. Awaiting your reply. Thank you in advance. Sincerely, Sayan -- -- *Sayan Chatterjee* Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP: Creating animation from multiple plots
Hi Sayan, On Wed, Mar 27, 2013 at 4:14 PM, Sayan Chatterjee sayanchatter...@gmail.com wrote: Dear All, I am a newbie to Python but have a fair know how of other languages i.e C etc. I want to run an astrophysical simulation in Python. All I have to do it to generate a set of 'plots' depending on a varying parameter and then stitch them up. 1) Is it possible to automatically generate different data files( say in the orders of 1000) with different names depending on a parameter? It certainly is. Are you talking about the file names being file_1001.txt, file_1002.txt and so on? If yes, let's say your parameter values are stored in param. Then something like this would do the trick: param_values = [1000,1001, 1005, 2001] for param in param_values: fname = 'file_' + str(param) # write to file fname # # Sorry if its different from what you are looking for. But yes, its certainly possible. 2) Is it possible to plot the data sets right from Python itself and save the plots in different jpeg files to stitched upon later on. It is possible to generate plots and save each as JPEGs. [1]. What do you mean by stitching together? [1] http://stackoverflow.com/questions/8827016/matplotlib-savefig-in-jpeg-format Best, Amit -- http://amitsaha.github.com/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP: Creating animation from multiple plots
On Wed, Mar 27, 2013 at 4:23 PM, Amit Saha amitsaha...@gmail.com wrote: Hi Sayan, On Wed, Mar 27, 2013 at 4:14 PM, Sayan Chatterjee sayanchatter...@gmail.com wrote: Dear All, I am a newbie to Python but have a fair know how of other languages i.e C etc. I want to run an astrophysical simulation in Python. All I have to do it to generate a set of 'plots' depending on a varying parameter and then stitch them up. 1) Is it possible to automatically generate different data files( say in the orders of 1000) with different names depending on a parameter? It certainly is. Are you talking about the file names being file_1001.txt, file_1002.txt and so on? If yes, let's say your parameter values are stored in param. Then something like this would do the trick: param_values = [1000,1001, 1005, 2001] for param in param_values: fname = 'file_' + str(param) # write to file fname # # Sorry if its different from what you are looking for. But yes, its certainly possible. 2) Is it possible to plot the data sets right from Python itself and save the plots in different jpeg files to stitched upon later on. It is possible to generate plots and save each as JPEGs. [1]. What do you mean by stitching together? You probably meant creating an animation from them. Yes, it is certainly possible. I will try to find a link which makes it really easy to create an animation out of a bunch of images. Which operating system are you on? -Amit. -- http://amitsaha.github.com/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP: Creating animation from multiple plots
Thanks a lot for your prompt reply. 1. Yes. This is exactly what I wanted. Creating a bunch of data sets and then writing script to plot them using gnuplot, but if something can produce directly 'plots' it will certainly be helpful. 2. Yes. By stitching them up I meant an animation.Sorry for the ambiguity. Exactly how we can do it Octave. Pls see this link: http://www.krizka.net/2009/11/06/creating-animations-with-octave/ I think Python is THE language, which may come to an immediate rescue. My OS is Linux Mint (Gnome 3) Sayan On 27 March 2013 11:57, Amit Saha amitsaha...@gmail.com wrote: On Wed, Mar 27, 2013 at 4:23 PM, Amit Saha amitsaha...@gmail.com wrote: Hi Sayan, On Wed, Mar 27, 2013 at 4:14 PM, Sayan Chatterjee sayanchatter...@gmail.com wrote: Dear All, I am a newbie to Python but have a fair know how of other languages i.e C etc. I want to run an astrophysical simulation in Python. All I have to do it to generate a set of 'plots' depending on a varying parameter and then stitch them up. 1) Is it possible to automatically generate different data files( say in the orders of 1000) with different names depending on a parameter? It certainly is. Are you talking about the file names being file_1001.txt, file_1002.txt and so on? If yes, let's say your parameter values are stored in param. Then something like this would do the trick: param_values = [1000,1001, 1005, 2001] for param in param_values: fname = 'file_' + str(param) # write to file fname # # Sorry if its different from what you are looking for. But yes, its certainly possible. 2) Is it possible to plot the data sets right from Python itself and save the plots in different jpeg files to stitched upon later on. It is possible to generate plots and save each as JPEGs. [1]. What do you mean by stitching together? You probably meant creating an animation from them. Yes, it is certainly possible. I will try to find a link which makes it really easy to create an animation out of a bunch of images. Which operating system are you on? -Amit. -- http://amitsaha.github.com/ -- -- *Sayan Chatterjee* Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP: Creating animation from multiple plots
On Wed, Mar 27, 2013 at 4:36 PM, Sayan Chatterjee sayanchatter...@gmail.com wrote: Thanks a lot for your prompt reply. 1. Yes. This is exactly what I wanted. Creating a bunch of data sets and then writing script to plot them using gnuplot, but if something can produce directly 'plots' it will certainly be helpful. Yes, indeed it is possible. You may want to explore matplotlib a bit. You can start with this tutorial [1]. [1] http://www.loria.fr/~rougier/teaching/matplotlib/ 2. Yes. By stitching them up I meant an animation.Sorry for the ambiguity. Exactly how we can do it Octave. Pls see this link: http://www.krizka.net/2009/11/06/creating-animations-with-octave/ Right, yes, if you see it uses mencoder/ffmpeg to create the animation. So, if you save your individual plots and then use one of these tools, you should be able to get the animation done. Matplotlib itself seems to have some Animated plotting capabilities, but I haven't had any experience with them. Best, Amit. -- http://amitsaha.github.com/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP: Creating animation from multiple plots
Yes, ffmpeg will do if multiple plots can be generated using mathplotlib . I'll look up the links you provided and get back to you, if I can't figure it out. :) On 27 March 2013 12:12, Amit Saha amitsaha...@gmail.com wrote: On Wed, Mar 27, 2013 at 4:36 PM, Sayan Chatterjee sayanchatter...@gmail.com wrote: Thanks a lot for your prompt reply. 1. Yes. This is exactly what I wanted. Creating a bunch of data sets and then writing script to plot them using gnuplot, but if something can produce directly 'plots' it will certainly be helpful. Yes, indeed it is possible. You may want to explore matplotlib a bit. You can start with this tutorial [1]. [1] http://www.loria.fr/~rougier/teaching/matplotlib/ 2. Yes. By stitching them up I meant an animation.Sorry for the ambiguity. Exactly how we can do it Octave. Pls see this link: http://www.krizka.net/2009/11/06/creating-animations-with-octave/ Right, yes, if you see it uses mencoder/ffmpeg to create the animation. So, if you save your individual plots and then use one of these tools, you should be able to get the animation done. Matplotlib itself seems to have some Animated plotting capabilities, but I haven't had any experience with them. Best, Amit. -- http://amitsaha.github.com/ -- -- *Sayan Chatterjee* Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP: Creating animation from multiple plots
Hi Amit, fo = fopen('fname','r+') fo.write(%d %d,j,counter) Is giving the following error: File ZA.py, line 30, in module fo = open('fname','r+') IOError: [Errno 2] No such file or directory: 'fname' Where is the mistake? Cheers, Sayan On 27 March 2013 12:20, Amit Saha amitsaha...@gmail.com wrote: On Wed, Mar 27, 2013 at 4:49 PM, Sayan Chatterjee sayanchatter...@gmail.com wrote: Yes, ffmpeg will do if multiple plots can be generated using mathplotlib . I'll look up the links you provided and get back to you, if I can't figure it out. :) Sure, good luck! :) On 27 March 2013 12:12, Amit Saha amitsaha...@gmail.com wrote: On Wed, Mar 27, 2013 at 4:36 PM, Sayan Chatterjee sayanchatter...@gmail.com wrote: Thanks a lot for your prompt reply. 1. Yes. This is exactly what I wanted. Creating a bunch of data sets and then writing script to plot them using gnuplot, but if something can produce directly 'plots' it will certainly be helpful. Yes, indeed it is possible. You may want to explore matplotlib a bit. You can start with this tutorial [1]. [1] http://www.loria.fr/~rougier/teaching/matplotlib/ 2. Yes. By stitching them up I meant an animation.Sorry for the ambiguity. Exactly how we can do it Octave. Pls see this link: http://www.krizka.net/2009/11/06/creating-animations-with-octave/ Right, yes, if you see it uses mencoder/ffmpeg to create the animation. So, if you save your individual plots and then use one of these tools, you should be able to get the animation done. Matplotlib itself seems to have some Animated plotting capabilities, but I haven't had any experience with them. Best, Amit. -- http://amitsaha.github.com/ -- -- Sayan Chatterjee Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org -- http://amitsaha.github.com/ -- -- *Sayan Chatterjee* Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP: Creating animation from multiple plots
On Wed, Mar 27, 2013 at 11:59 AM, Sayan Chatterjee sayanchatter...@gmail.com wrote: Hi Amit, fo = fopen('fname','r+') fo.write(%d %d,j,counter) Is giving the following error: File ZA.py, line 30, in module fo = open('fname','r+') IOError: [Errno 2] No such file or directory: 'fname' Where is the mistake? Where is the file called 'fname'? It must exist and be in the current directory Cheers, Sayan On 27 March 2013 12:20, Amit Saha amitsaha...@gmail.com wrote: On Wed, Mar 27, 2013 at 4:49 PM, Sayan Chatterjee sayanchatter...@gmail.com wrote: Yes, ffmpeg will do if multiple plots can be generated using mathplotlib . I'll look up the links you provided and get back to you, if I can't figure it out. :) Sure, good luck! :) On 27 March 2013 12:12, Amit Saha amitsaha...@gmail.com wrote: On Wed, Mar 27, 2013 at 4:36 PM, Sayan Chatterjee sayanchatter...@gmail.com wrote: Thanks a lot for your prompt reply. 1. Yes. This is exactly what I wanted. Creating a bunch of data sets and then writing script to plot them using gnuplot, but if something can produce directly 'plots' it will certainly be helpful. Yes, indeed it is possible. You may want to explore matplotlib a bit. You can start with this tutorial [1]. [1] http://www.loria.fr/~rougier/teaching/matplotlib/ 2. Yes. By stitching them up I meant an animation.Sorry for the ambiguity. Exactly how we can do it Octave. Pls see this link: http://www.krizka.net/2009/11/06/creating-animations-with-octave/ Right, yes, if you see it uses mencoder/ffmpeg to create the animation. So, if you save your individual plots and then use one of these tools, you should be able to get the animation done. Matplotlib itself seems to have some Animated plotting capabilities, but I haven't had any experience with them. Best, Amit. -- http://amitsaha.github.com/ -- -- Sayan Chatterjee Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org -- http://amitsaha.github.com/ -- -- *Sayan Chatterjee* Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Joel Goldstick http://joelgoldstick.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP: Creating animation from multiple plots
Hello, On 27 March 2013 15:59, Sayan Chatterjee sayanchatter...@gmail.com wrote: Hi Amit, fo = fopen('fname','r+') fo.write(%d %d,j,counter) Is giving the following error: File ZA.py, line 30, in module fo = open('fname','r+') IOError: [Errno 2] No such file or directory: 'fname' Where is the mistake? You are trying to open a file named literally fname due to putting it in quotes, you probably want to drop the quotes. Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP: Creating animation from multiple plots
for t in range(0,200): fname = 'file_' + str(t) So it will assign fname values file_0, file_1 so on. Dropping the quotes is giving me IOError: [Errno 2] No such file or directory: 'file_0' Indeed the file is not present. In C we write,if we have to record data in a file FILE *fp fp = fopen(file.dat,w) Here I want to write different data sets in files having different name i.e I want to create the files with the data sets. I am quite new to Python, so you can assume zero knowledge while answering. Thanks for your support. :) On 27 March 2013 21:38, Walter Prins wpr...@gmail.com wrote: Hello, On 27 March 2013 15:59, Sayan Chatterjee sayanchatter...@gmail.comwrote: Hi Amit, fo = fopen('fname','r+') fo.write(%d %d,j,counter) Is giving the following error: File ZA.py, line 30, in module fo = open('fname','r+') IOError: [Errno 2] No such file or directory: 'fname' Where is the mistake? You are trying to open a file named literally fname due to putting it in quotes, you probably want to drop the quotes. Walter -- -- *Sayan Chatterjee* Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP: Creating animation from multiple plots
Putting w instead of r+ probably solves the problem. The error is not showing now. On 27 March 2013 21:47, Sayan Chatterjee sayanchatter...@gmail.com wrote: for t in range(0,200): fname = 'file_' + str(t) So it will assign fname values file_0, file_1 so on. Dropping the quotes is giving me IOError: [Errno 2] No such file or directory: 'file_0' Indeed the file is not present. In C we write,if we have to record data in a file FILE *fp fp = fopen(file.dat,w) Here I want to write different data sets in files having different name i.e I want to create the files with the data sets. I am quite new to Python, so you can assume zero knowledge while answering. Thanks for your support. :) On 27 March 2013 21:38, Walter Prins wpr...@gmail.com wrote: Hello, On 27 March 2013 15:59, Sayan Chatterjee sayanchatter...@gmail.comwrote: Hi Amit, fo = fopen('fname','r+') fo.write(%d %d,j,counter) Is giving the following error: File ZA.py, line 30, in module fo = open('fname','r+') IOError: [Errno 2] No such file or directory: 'fname' Where is the mistake? You are trying to open a file named literally fname due to putting it in quotes, you probably want to drop the quotes. Walter -- -- *Sayan Chatterjee* Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org -- -- *Sayan Chatterjee* Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP: Creating animation from multiple plots
You were opening the file for reading, rather than writing. It therefore was expecting to find a file. Change fo = open('fname','r+') to fo = open('fname','w') Bodsda On 27 March 2013 16:17, Sayan Chatterjee sayanchatter...@gmail.com wrote: for t in range(0,200): fname = 'file_' + str(t) So it will assign fname values file_0, file_1 so on. Dropping the quotes is giving me IOError: [Errno 2] No such file or directory: 'file_0' Indeed the file is not present. In C we write,if we have to record data in a file FILE *fp fp = fopen(file.dat,w) Here I want to write different data sets in files having different name i.e I want to create the files with the data sets. I am quite new to Python, so you can assume zero knowledge while answering. Thanks for your support. :) On 27 March 2013 21:38, Walter Prins wpr...@gmail.com wrote: Hello, On 27 March 2013 15:59, Sayan Chatterjee sayanchatter...@gmail.com wrote: Hi Amit, fo = fopen('fname','r+') fo.write(%d %d,j,counter) Is giving the following error: File ZA.py, line 30, in module fo = open('fname','r+') IOError: [Errno 2] No such file or directory: 'fname' Where is the mistake? You are trying to open a file named literally fname due to putting it in quotes, you probably want to drop the quotes. Walter -- -- Sayan Chatterjee Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP: Creating animation from multiple plots
Oh yes, thanks. That worked. :) On 27 March 2013 21:58, Bod Soutar bod...@googlemail.com wrote: You were opening the file for reading, rather than writing. It therefore was expecting to find a file. Change fo = open('fname','r+') to fo = open('fname','w') Bodsda On 27 March 2013 16:17, Sayan Chatterjee sayanchatter...@gmail.com wrote: for t in range(0,200): fname = 'file_' + str(t) So it will assign fname values file_0, file_1 so on. Dropping the quotes is giving me IOError: [Errno 2] No such file or directory: 'file_0' Indeed the file is not present. In C we write,if we have to record data in a file FILE *fp fp = fopen(file.dat,w) Here I want to write different data sets in files having different name i.e I want to create the files with the data sets. I am quite new to Python, so you can assume zero knowledge while answering. Thanks for your support. :) On 27 March 2013 21:38, Walter Prins wpr...@gmail.com wrote: Hello, On 27 March 2013 15:59, Sayan Chatterjee sayanchatter...@gmail.com wrote: Hi Amit, fo = fopen('fname','r+') fo.write(%d %d,j,counter) Is giving the following error: File ZA.py, line 30, in module fo = open('fname','r+') IOError: [Errno 2] No such file or directory: 'fname' Where is the mistake? You are trying to open a file named literally fname due to putting it in quotes, you probably want to drop the quotes. Walter -- -- Sayan Chatterjee Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- -- *Sayan Chatterjee* Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP: Creating animation from multiple plots
Sayan Chatterjee wrote: for t in range(0,200): fname = 'file_' + str(t) So it will assign fname values file_0, file_1 so on. Dropping the quotes is giving me IOError: [Errno 2] No such file or directory: 'file_0' Indeed the file is not present. In C we write,if we have to record data in a file FILE *fp fp = fopen(file.dat,w) Here I want to write different data sets in files having different name i.e I want to create the files with the data sets. I am quite new to Python, so you can assume zero knowledge while answering. Thanks for your support. :) If you try to open a non-existent file in r+ mode in C you should get an error, too. The following C code FILE * f; int i; char filename[100]; for (i=0; i10; i++) { sprintf(filename, foo%d.dat, i); FILE * f = fopen(filename, w); /* write stuff to file */ ... fclose(f); } translates into this piece of Python: for i in range(10): filename = foo%d.dat % i with open(filename, w) as f: # write stuff to file ... ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor