I've got a script that takes the output of a separate C++ executable and creates a scatter plot/bifurcation diagram of the resulting data. The application context is to look at angle values versus the driving force by iterating through multiple values of a driving force to get the resulting angle and stroboscopically sampling the results, as a problem regarding a nonlinearly damped driven pendulum from a course on computational physics
import os
import sys
import numpy as np
import matplotlib.pyplot as plt
gbl = 1.0
kappa = 0.5
T_D = 9.424778
ic_ang = 0.1
ic_avel = 0.0
t_final = 200
Nstep = 7500
method = "runge_kutta"
ic_ang = 0.1
Fmin = 0.8
Fmax = 1.6
F_D = float(Fmin)
tstep = T_D/(t_final/Nstep)
Nrep = 3 * tstep
select =[]
step = 0.01
Nite = (Fmax-Fmin)/step
rng = int(Nite-1)
for i in range(rng):
pfile= open('param.dat','w')
pfile.write('%f %f %f %f\n' %(gbl,kappa,F_D,T_D))
pfile.write('%f %f %f\n'%(ic_ang,ic_avel,t_final))
pfile.write('%d %s\n'%(Nstep,method))
pfile.close()
os.system('./a.out > bif.log')
with open("data.out",'r') as datafile:
data=datafile.readlines()
select=data[-Nrep:Nstep:int(tstep)]
for j in select:
plt.plot(F_D, j, "o", color='b', markersize=0.3)
print(F_D,j)
F_D += step
plt.xlabel(r'$F_D$')
plt.ylabel(r'$\theta_{repeat}$')
#plt.xticks([])
plt.yticks([])
plt.show()
However, when I try to run the script I get
Traceback (most recent call last):
File "bif.py", line 45, in <module>
plt.plot(F_D, j, "o", color='b',markersize=0.3)
File"/System/Library/Frameworks/Python.framework/Versions/2.7/
Extras/lib/pyt hon/matplotlib/pyplot.py", line 2987, in plot
ret = ax.plot(*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/
Extras/lib/python/matplotlib/axes.py", line 4138, in plot
self.add_line(line)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/
Extras/lib/python/matplotlib/axes.py", line 1497, in add_line
self._update_line_limits(line)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/
Extras/lib/python/matplotlib/axes.py", line 1508, in
_update_line_limits
path = line.get_path()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/
Extras/lib/python/matplotlib/lines.py", line 743, in get_path
self.recache()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/
Extras/lib/python/matplotlib/lines.py", line 429, in recache
y = np.asarray(yconv, np.float_)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/
Extras/lib/python/numpy/core/numeric.py", line 460, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: invalid literal for float(): 0 0.1 0 0.004995834722
Modifying some of the values to try and debug the script raises a separate exception
Traceback (most recent call last):
File "bif.py", line 24, in <module>
tstep = T_D/(t_final/Nstep)
ZeroDivisionError: float division by zero
I am extremely new to Python so neither one of these exceptions makes much sense to me. However, as Nstep
, t_final
, and T_D
all have finite values, there is no reason (that I can see anyhow) for a dividing by zero error.
I see possible errors for the ValueError
as well, as the output in the 1st and 3rd columns (time and angular velocity) aren't float values as they should be. I don't, however, know why these values aren't being converted to a float as they should be.
Any help would be very much appreciated.
EDIT:THIS ISSUE HAS BEEN SOLVED