## matplotlib-users

 [Matplotlib-users] Script hanging during plot of Runge-Kutta From: surfcast23 - 2012-02-20 05:08:42 Attachments: Message as HTML ```Hi I wrote the following script, but it hangs right after plt.show(). I would really appreciate it if someone could take a look and let me know where I'm messing up. Thanks in advance from numpy import * import matplotlib.pyplot as plt #H=p^2/2-cosq #p=dp=-dH/dq #q=dq=dH/dp t = 0 h = 0.5 pfa = [] #Create arrays that will hold pf,qf values qfa = [] while t < 10: q = 1+t p = -sin(q+t) p1 = p q1 = q p2 = p + h/2*q1 q2 = q + h/2*p1 p3 = p+ h/2*q2 q3 = q+ h/2*p2 p4 = p+ h/2*q3 q4 = q+ h/2*p4 pf = (p +(h/6)*(p1+2*p2+3*p3+p4)) qf = (q +(h/6)*(q1+2*q2+3*q3+q4)) #pf = log10(pf) #Convert to log scale #qf = log10(qf) pfa.append(pf) #append arrays qfa.append(qf) t += h #increase time step print("test") plt.plot(pfa,qfa) print("test1") plt.show() print("tes2t") -- View this message in context: http://old.nabble.com/Script-hanging-during-plot-of-Runge-Kutta-tp33354840p33354840.html Sent from the matplotlib - users mailing list archive at Nabble.com. ```
 Re: [Matplotlib-users] Script hanging during plot of Runge-Kutta From: Eric Firing - 2012-02-20 05:25:51 ```On 02/19/2012 07:08 PM, surfcast23 wrote: > > Hi I wrote the following script, but it hangs right after plt.show(). I would > really appreciate it if someone could take a look and let me know where I'm > messing up. Thanks in advance That's what show() does in a script--it displays the plot and blocks execution until you close the window. It can be more complicated than that depending on the version of mpl you are running. So, what version are you running, and what is the behavior you are trying to achieve? An animation? Eric > > from numpy import * > import matplotlib.pyplot as plt > > #H=p^2/2-cosq > #p=dp=-dH/dq > #q=dq=dH/dp > > t = 0 > h = 0.5 > pfa = [] #Create arrays that will hold pf,qf values > qfa = [] > > while t< 10: > q = 1+t > p = -sin(q+t) > > p1 = p > q1 = q > p2 = p + h/2*q1 > q2 = q + h/2*p1 > p3 = p+ h/2*q2 > q3 = q+ h/2*p2 > p4 = p+ h/2*q3 > q4 = q+ h/2*p4 > pf = (p +(h/6)*(p1+2*p2+3*p3+p4)) > qf = (q +(h/6)*(q1+2*q2+3*q3+q4)) > #pf = log10(pf) #Convert to log scale > #qf = log10(qf) > pfa.append(pf) #append arrays > qfa.append(qf) > t += h #increase time step > > print("test") > plt.plot(pfa,qfa) > print("test1") > plt.show() > print("tes2t") > > > > ```
 Re: [Matplotlib-users] Script hanging during plot of Runge-Kutta From: Eric Firing - 2012-02-20 06:19:24 ```On 02/19/2012 07:46 PM, Khary Richardson wrote: > Hi Eric, > > Ok I guess I have a bigger problem. The plot window opens,but nothing > is plotted. I thought that the blank window was because the code was > hanging and not plotting. I had it work once and plot, but now I just > get the blank window. Khary, (Please keep correspondence on the list so others can jump in, and whatever answer emerges is available to others.) You need to provide more information: operating system, mpl version, backend, how you installed it. Some systematic troubleshooting is also in order. Start here: http://matplotlib.sourceforge.net/faq/index.html. Eric > > Khary > > On Mon, Feb 20, 2012 at 12:25 AM, Eric Firing > wrote: > > On 02/19/2012 07:08 PM, surfcast23 wrote: > > > > Hi I wrote the following script, but it hangs right after > plt.show(). I would > > really appreciate it if someone could take a look and let me know > where I'm > > messing up. Thanks in advance > > That's what show() does in a script--it displays the plot and blocks > execution until you close the window. It can be more complicated than > that depending on the version of mpl you are running. So, what version > are you running, and what is the behavior you are trying to achieve? An > animation? > > Eric > > > > > from numpy import * > > import matplotlib.pyplot as plt > > > > #H=p^2/2-cosq > > #p=dp=-dH/dq > > #q=dq=dH/dp > > > > t = 0 > > h = 0.5 > > pfa = [] #Create arrays that will hold > pf,qf values > > qfa = [] > > > > while t< 10: > > q = 1+t > > p = -sin(q+t) > > > > p1 = p > > q1 = q > > p2 = p + h/2*q1 > > q2 = q + h/2*p1 > > p3 = p+ h/2*q2 > > q3 = q+ h/2*p2 > > p4 = p+ h/2*q3 > > q4 = q+ h/2*p4 > > pf = (p +(h/6)*(p1+2*p2+3*p3+p4)) > > qf = (q +(h/6)*(q1+2*q2+3*q3+q4)) > > #pf = log10(pf) #Convert to log scale > > #qf = log10(qf) > > pfa.append(pf) #append arrays > > qfa.append(qf) > > t += h #increase time step > > > > print("test") > > plt.plot(pfa,qfa) > > print("test1") > > plt.show() > > print("tes2t") > > > > > > > > > > > ------------------------------------------------------------------------------ > Try before you buy = See our experts in action! > The most comprehensive online learning library for Microsoft developers > is just \$99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, > Metro Style Apps, more. Free future releases when you subscribe now! > http://p.sf.net/sfu/learndevnow-dev2 > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > > > > -- > StriperCoast SurfCasters Club > ```
 Re: [Matplotlib-users] Script hanging during plot of Runge-Kutta From: Scott Sinclair - 2012-02-21 10:04:34 ```On 20 February 2012 07:08, surfcast23 wrote: > > Hi I wrote the following script, but it hangs right after plt.show(). I would > really appreciate it if someone could take a look and let me know where I'm > messing up. Thanks in advance Your script works fine for me. It's just that on the first pass through the loop you're calling plt.plot() and asking it to plot a line defined by a single point, so the plot is blank. If you close the plot you'll see that the next one has a line. Close that and you'll see a line composed of two segments etc... Alternatively, reduce the indentation level of your plot command and plot the entire trace after the loop completes. Cheers, Scott ```