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.
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
···
On 02/19/2012 07:08 PM, surfcast23 wrote:
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")
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
···
On 20 February 2012 07:08, surfcast23 <surfcast23@...287...> 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