Skip to content
Snippets Groups Projects
Commit 1d22857b authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Jakub Klinkovský
Browse files

Fixed line indenting in Python ODE examples scritps.

parent bd5f3667
No related branches found
No related tags found
1 merge request!125ODE solvers
......@@ -12,18 +12,17 @@ x_lst = []
y_lst = []
z_lst = []
for line in f:
line = line.strip()
a = line.split()
x_lst.append( float( a[ 0 ] ) )
y_lst.append( float( a[ 1 ] ) )
z_lst.append( float( a[ 2 ] ) )
line = line.strip()
a = line.split()
x_lst.append( float( a[ 0 ] ) )
y_lst.append( float( a[ 1 ] ) )
z_lst.append( float( a[ 2 ] ) )
x = np.array(x_lst)
y = np.array(y_lst)
z = np.array(z_lst)
fig = plt.figure()
#ax = fig.gca(projection='3d')
ax = Axes3D(fig)
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
ax.plot(x, y, z, label='Lorenz attractor')
......
......@@ -24,33 +24,33 @@ parameters = []
data = {}
size = 0
for line in f:
line = line.strip()
a = line.split()
if not a:
continue
if a[ 0 ] == "#":
if x_lst:
parameters_tuple = ( current_sigma, current_rho, current_beta )
parameters.append( parameters_tuple )
data_tuple = ( np.array( x_lst ), np.array( y_lst ), np.array( z_lst ) )
data[ parameters_tuple ] = data_tuple
x_lst.clear()
y_lst.clear()
z_lst.clear()
line = line.strip()
a = line.split()
if not a:
continue
if a[ 0 ] == "#":
if x_lst:
parameters_tuple = ( current_sigma, current_rho, current_beta )
parameters.append( parameters_tuple )
data_tuple = ( np.array( x_lst ), np.array( y_lst ), np.array( z_lst ) )
data[ parameters_tuple ] = data_tuple
x_lst.clear()
y_lst.clear()
z_lst.clear()
current_sigma = float( a[ 2 ] )
current_rho = float( a[ 4 ] )
current_beta = float( a [ 6 ] )
if current_sigma not in sigma_lst:
sigma_lst.append( current_sigma )
if current_rho not in rho_lst:
rho_lst.append( current_rho )
if current_beta not in beta_lst:
beta_lst.append( current_beta )
else:
x_lst.append( float( a[ 0 ] ) )
y_lst.append( float( a[ 1 ] ) )
z_lst.append( float( a[ 2 ] ) )
current_sigma = float( a[ 2 ] )
current_rho = float( a[ 4 ] )
current_beta = float( a [ 6 ] )
if current_sigma not in sigma_lst:
sigma_lst.append( current_sigma )
if current_rho not in rho_lst:
rho_lst.append( current_rho )
if current_beta not in beta_lst:
beta_lst.append( current_beta )
else:
x_lst.append( float( a[ 0 ] ) )
y_lst.append( float( a[ 1 ] ) )
z_lst.append( float( a[ 2 ] ) )
parameters_tuple = ( current_sigma, current_rho, current_beta )
parameters.append( parameters_tuple )
data_tuple = ( np.array( x_lst ), np.array( y_lst ), np.array( z_lst ) )
......@@ -59,30 +59,30 @@ data[ parameters_tuple ] = data_tuple
sigma_n = len( sigma_lst )
sigma_idx = 1
for sigma in sigma_lst:
rho_n = len( rho_lst )
beta_n = len( beta_lst )
rho_n = len( rho_lst )
beta_n = len( beta_lst )
fig, ax = plt.subplots( rho_n, beta_n, figsize=(8, 8), sharey=True, sharex=True )
fig.suptitle( f'$\sigma={sigma}$')
#ax = Axes3D(fig) dos not work with ax indexing
rho_idx = 0
beta_idx = 0
for rho in rho_lst:
for beta in beta_lst:
parameters_tuple = ( sigma, rho, beta )
data_tuple = data[ parameters_tuple ]
ax[ rho_idx, beta_idx ].plot( data_tuple[ 1 ], data_tuple[ 2 ], linewidth=1.0 )
if beta_idx == 0:
ax[ rho_idx, beta_idx ].set_ylabel( f'$\\rho={rho}$' )
if rho_idx == rho_n-1:
ax[ rho_idx, beta_idx ].set_xlabel( f'$\\beta={beta}$' )
beta_idx = beta_idx + 1
beta_idx = 0
rho_idx = rho_idx + 1
fig, ax = plt.subplots( rho_n, beta_n, figsize=(8, 8), sharey=True, sharex=True )
fig.suptitle( f'$\sigma={sigma}$')
#ax = Axes3D(fig) dos not work with ax indexing
rho_idx = 0
beta_idx = 0
for rho in rho_lst:
for beta in beta_lst:
parameters_tuple = ( sigma, rho, beta )
data_tuple = data[ parameters_tuple ]
ax[ rho_idx, beta_idx ].plot( data_tuple[ 1 ], data_tuple[ 2 ], linewidth=1.0 )
if beta_idx == 0:
ax[ rho_idx, beta_idx ].set_ylabel( f'$\\rho={rho}$' )
if rho_idx == rho_n-1:
ax[ rho_idx, beta_idx ].set_xlabel( f'$\\beta={beta}$' )
beta_idx = beta_idx + 1
beta_idx = 0
rho_idx = rho_idx + 1
plt.savefig( f"{sys.argv[2]}-{sigma_idx}.png" )
sigma_idx = sigma_idx + 1
plt.close(fig)
plt.savefig( f"{sys.argv[2]}-{sigma_idx}.png" )
sigma_idx = sigma_idx + 1
plt.close(fig)
......
......@@ -10,10 +10,10 @@ f = open( sys.argv[1], 'r' )
x_lst = []
y_lst = []
for line in f:
line = line.strip()
a = line.split()
x_lst.append( float( a[ 0 ] ) )
y_lst.append( float( a[ 1 ] ) )
line = line.strip()
a = line.split()
x_lst.append( float( a[ 0 ] ) )
y_lst.append( float( a[ 1 ] ) )
x = np.array(x_lst)
y = np.array(y_lst)
......
......@@ -10,34 +10,29 @@ f = open( sys.argv[1], 'r' )
data_lst = []
size = 0
for line in f:
line = line.strip()
a = line.split()
aux = []
for num in a:
aux.append( float( num ) )
data_lst.append( aux )
line = line.strip()
a = line.split()
aux = []
for num in a:
aux.append( float( num ) )
data_lst.append( aux )
arrays = []
for a in data_lst:
arrays.append( np.array( a ) )
arrays.append( np.array( a ) )
#x = arrays[ 0 ]
#arrays.remove( 0 )
n = len( arrays )
print( n )
fig, ax = plt.subplots( 1, n-1, figsize=(15, 3), sharey=True )
#fig, ax = plt.subplots( 1, n-1, sharey=True )
idx = 0
for array in arrays:
if idx > 0:
ax[ idx - 1 ].plot(arrays[0], array, linewidth=2.0)
ax[ idx - 1 ].set_xlabel( "t" )
ax[ idx - 1 ].set_ylabel( "u(t)" )
# ax[ idx - 1 ].axis('equal')
idx = idx + 1
if idx > 0:
ax[ idx - 1 ].plot(arrays[0], array, linewidth=2.0)
ax[ idx - 1 ].set_xlabel( "t" )
ax[ idx - 1 ].set_ylabel( "u(t)" )
idx = idx + 1
plt.savefig( sys.argv[2] )
plt.close(fig)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment