Repository navigation
Expand file tree
/
Copy pathaverage.py
More file actions
493 lines (413 loc) · 19.5 KB
/
Copy pathaverage.py
File metadata and controls
493 lines (413 loc) · 19.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
import random
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
from scipy.integrate import quad
from scipy.optimize import curve_fit
import glob
import os
import pandas as pd
from PIL import Image
import re
from scipy.integrate import odeint
tmin = 0 # Minimum time
tmax = 4000 # Maximum time
show_fits = 0 # Show the exponential fits
fit = 'gompertz' #gompertz or exp
show_necro = 1
show_quiet_cycling = 1
show_vessels = False
local = 0
irradiation_first = 100000
irradiation_file = 'FRAC_25_frac_no_weekends.csv'
def plot_outliners(ax, x, y, y_min, y_max, color='black'):
for i in range(len(x)):
if y[i] < y_min[i] or y[i] > y_max[i]:
ax.plot(x[i], y[i], '.', color=color)
repo = "20240815_kunzlo_Linux/CONFIG_2024_example.py_214904"
csv_file = ''
#all repositories in repo:
#find csv file in repo
for filename in os.listdir(repo):
# Check if the file is a csv file
if filename.endswith('.csv'):
csv_file = filename
param_space = pd.read_csv(f'{repo}/{csv_file}', sep=' ', header=0)
print(param_space)
print(param_space.columns)
print(param_space.columns[1])
parameter = param_space.columns[1]
param = np.array(param_space[parameter])
number_of_iterations = len(param_space['Iteration'])
#iter = [1,2,3,4,5,6,7,8,9]
iter = []
if iter == []:
iter = [i for i in range(number_of_iterations)]
paths = [f'{repo}/iter{i}/DataOutput/' for i in iter]
#remove paths 4
print(paths)
if local: paths = ['DataOutput/']
number_cells_list = []
necrotic_cells_list = []
cycling_cells_list = []
quiescent_cells_list = []
tumor_size_list = []
tumor_size_free_list = []
number_vessels_list = []
times_list = []
for path in paths:
# number_cells = np.load(f'{path}number_tumor_cells.npy', allow_pickle=True)
necrotic_cells = np.load(f'{path}number_necrotic_cells.npy', allow_pickle=True)
cycling_cells = np.load(f'{path}number_cycling_cells.npy', allow_pickle=True)
quiescent_cells = np.load(f'{path}number_quiescent_cells.npy', allow_pickle=True)
number_cells = cycling_cells + quiescent_cells + necrotic_cells
tumor_size = np.load(f'{path}tumor_size.npy', allow_pickle=True)
tumor_size_free = np.load(f'{path}tumor_size_free.npy', allow_pickle=True)
# tumor_size_free = tumor_size - tumor_size_free
number_vessels = np.load(f'{path}number_vessels.npy', allow_pickle=True)
times = np.load(f'{path}times.npy', allow_pickle=True)
# Find the indices of the times that are within the time range
idx = np.where((times >= tmin) & (times<=tmax))
# Filter the arrays to only include the data between tmin and tmax
number_cells = number_cells[idx]
tumor_size = tumor_size[idx]
tumor_size_free = tumor_size_free[idx]
necrotic_cells = necrotic_cells[idx]
cycling_cells = cycling_cells[idx]
quiescent_cells = quiescent_cells[idx]
number_vessels = number_vessels[idx]
times = times[idx]
# Append the filtered arrays to the lists
number_cells_list.append(number_cells)
tumor_size_list.append(tumor_size)
tumor_size_free_list.append(tumor_size_free)
necrotic_cells_list.append(necrotic_cells)
cycling_cells_list.append(cycling_cells)
quiescent_cells_list.append(quiescent_cells)
number_vessels_list.append(number_vessels)
times_list.append(times)
# Fit the data to an exponential curve for each simulation and get the doubling time
doubling_times_number_cells = []
doubling_times_tumor_size = []
dpi = 300
fig, axes = plt.subplots(2, 1, figsize=(5, 10), dpi=dpi)
#for each y point, find the average and SD
max_times = []
for array in times_list:
if len(array) > len(max_times):
max_times = array
number_cells_average = [] ; number_cells_sd = []
necrotic_cells_average = [] ; necrotic_cells_sd = []
cycling_cells_average = [] ; cycling_cells_sd = []
quiescent_cells_average = [] ; quiescent_cells_sd = []
tumor_size_average = [] ; tumor_size_sd = []
tumor_size_free_average = [] ; tumor_size_free_sd = []
number_vessels_average = [] ; number_vessels_sd = []
for t in max_times:
idd = np.where(max_times == t)
number_cells = []
necrotic_cells = []
cycling_cells = []
quiescent_cells = []
tumor_size = []
tumor_size_free = []
number_vessels = []
for i in range(len(paths)):
if idd[0][0] < len(number_cells_list[i]):
number_cells.append(number_cells_list[i][idd])
necrotic_cells.append(necrotic_cells_list[i][idd])
cycling_cells.append(cycling_cells_list[i][idd])
quiescent_cells.append(quiescent_cells_list[i][idd])
tumor_size.append(tumor_size_list[i][idd])
tumor_size_free.append(tumor_size_free_list[i][idd])
number_vessels.append(number_vessels_list[i][idd])
number_cells_average.append(np.mean(number_cells))
necrotic_cells_average.append(np.mean(necrotic_cells))
cycling_cells_average.append(np.mean(cycling_cells))
quiescent_cells_average.append(np.mean(quiescent_cells))
tumor_size_average.append(np.mean(tumor_size))
tumor_size_free_average.append(np.mean(tumor_size_free))
number_vessels_average.append(np.mean(number_vessels))
number_cells_sd.append(np.std(number_cells))
necrotic_cells_sd.append(np.std(necrotic_cells))
cycling_cells_sd.append(np.std(cycling_cells))
quiescent_cells_sd.append(np.std(quiescent_cells))
tumor_size_sd.append(np.std(tumor_size))
tumor_size_free_sd.append(np.std(tumor_size_free))
number_vessels_sd.append(np.std(number_vessels))
if t == 500 or t == 1000 or t == 1500 or t == 2000 or t == 2500 or t == 3000 or t == 3500 or t == 4000:
print('Average number of cells at time', t, ':', number_cells_average[-1], 'SD:', number_cells_sd[-1])
print('Average tumor size at time', t, ':', tumor_size_average[-1], 'SD:', tumor_size_sd[-1])
#add in a csv file, with the repo name in a column and the average number of cells and tumor size at each time point
df = pd.DataFrame({'Repo': [repo], 'Time': [t], 'Number of Cells': [number_cells_average[-1]], 'Number of Cells SD' : [number_cells_sd[-1]], 'Tumor Size': [tumor_size_average[-1]], 'Tumor Size SD': [tumor_size_sd[-1]]})
df.to_csv('average_data.csv', mode='a', header=False)
times_average = max_times
# Fit number of cells
if fit == 'exp':
def func_cell(x, a, b):
return a * (np.exp(b * x)) + number_cells_average[0] - a
def func_volume(x, a, b):
return a * (np.exp(b * x)) + tumor_size_average[0] - a
p1 = (3000, 3e-3)
p2 = (1, 0.003)
elif fit == 'gompertz':
def func_cell(x, a, b):
return a * np.exp(np.log(number_cells_average[0]/a)*np.exp(-b * x))
def func_volume(x, a, b):
return a * np.exp(np.log(tumor_size_average[0]/a)*np.exp(-b * x))
p1 = ( 3000000, 0.01)
p2 = ( 3000 , 0.01)
elif fit == 'exp-linear':
def func_cell(x, a, b, c, d, e):
return a * np.exp(b * x) + c * np.log(d * x) + e
def func_volume(x, a, b, c, d, e):
return a * np.exp(b * x) + c * np.log(d * x) + e
if show_fits:
popt, pcov = curve_fit(func_cell, max_times, number_cells_average, p0=p1, maxfev=100000)
axes[0].plot(times_average, number_cells_average, '-', label = 'Number of Cells', color='blue', alpha=0.8)
axes[0].fill_between(times_average, np.array(number_cells_average) - np.array(number_cells_sd), np.array(number_cells_average) + np.array(number_cells_sd), alpha=0.2, color='blue')
# for i in range(len(paths)):
# plot_outliners(axes[0], times_list[i], number_cells_list[i], np.array(number_cells_average) - np.array(number_cells_sd), np.array(number_cells_average) + np.array(number_cells_sd), color='black')
if show_necro:
axes[0].plot(times_average, necrotic_cells_average, '-', label = 'Necrotic Cells', color='black', alpha=0.8)
axes[0].fill_between(times_average, np.array(necrotic_cells_average) - np.array(necrotic_cells_sd), np.array(necrotic_cells_average) + np.array(necrotic_cells_sd), alpha=0.2, color='black')
if show_quiet_cycling:
axes[0].plot(times_average , cycling_cells_average , '-', label = 'Cycling Cells', color='red', alpha=0.8)
axes[0].fill_between(times_average, np.array(cycling_cells_average) - np.array(cycling_cells_sd), np.array(cycling_cells_average) + np.array(cycling_cells_sd), alpha=0.2, color='red')
axes[0].plot(times_average , quiescent_cells_average , '-', label = 'Quiescent Cells', color='green', alpha=0.8)
axes[0].fill_between(times_average, np.array(quiescent_cells_average) - np.array(quiescent_cells_sd), np.array(quiescent_cells_average) + np.array(quiescent_cells_sd), alpha=0.2, color='green')
if show_fits:
axes[0].plot(times_average , func_cell(times_average, *popt), '--', color='blue')
#diff fitting
axes[0].plot(times_average , number_cells_average- func_cell(times_average, *popt), '--', color='orange')
doubling_time = np.log(2) / popt[1]
if fit == 'gompertz':
print('Doubling time (Number of Cells):', doubling_time)
print('Max Carrying capacity:', popt[0])
elif fit == 'exp':
print('Doubling time (Number of Cells):', doubling_time)
print(popt)
doubling_times_number_cells.append(doubling_time)
# Fit tumor size
if show_fits:
popt, pcov = curve_fit(func_volume, times_average , tumor_size_average , p0=p2, maxfev=100000)
axes[1].plot(times_average, tumor_size_average, '-', color = 'black', markersize = 5, alpha=0.8, label='Total Tumor Volume')
axes[1].fill_between(times_average, np.array(tumor_size_average) - np.array(tumor_size_sd), np.array(tumor_size_average) + np.array(tumor_size_sd), alpha=0.2, color='black')
axes[1].plot(times_average, tumor_size_free_average, '-', color = 'purple', markersize = 5, alpha=0.8, label='Non-Necrotic Tumor Volume')
axes[1].fill_between(times_average, np.array(tumor_size_free_average) - np.array(tumor_size_free_sd), np.array(tumor_size_free_average) + np.array(tumor_size_free_sd), alpha=0.2, color='purple')
if show_fits:
axes[1].plot(times_list[i], func_volume(times_average, *popt), '--', color='black')#, label='fit '+parameter+': '+str(param[i]))
doubling_time = np.log(2)/popt[1]
doubling_times_tumor_size.append(doubling_time)
# # Set the x-axis ticks to show 1 day, 2 days, 3 days, etc.
xticks = [i for i in range(0, times_average[-1], 168)]
print(xticks)
xticklabels = [i for i in range(0, int(times_average[-1]/24)+1, 7)]
print(xticklabels)
axes[0].set_xticks(xticks)
axes[0].set_xticklabels(xticklabels)
axes[1].set_xticks(xticks)
axes[1].set_xticklabels(xticklabels)
#
# # Add vertical black arrows to show times of irradiation
# irradiation_times_cells = [irradiation[0] + i*irradiation[1] for i in range(0,irradiation[2])] # times of irradiation in hours
#read in from file
# irradiation_times_cells = []
# with open(irradiation_file, 'r') as f:
# for line in f:
# irradiation_times_cells.append(float(line) + irradiation_first)
#
# shift = 10000
# shift2 = 3
# for time in irradiation_times_cells:
# id = np.where(times_average == time)[0][0] # get index of time
# arrow1 = axes[0].annotate('', xy=(times_average[id], number_cells_average[id] + shift), xytext=(times_average[id], number_cells_average[id] + shift+1), arrowprops=dict(facecolor='black', width=1.5, headwidth=5))
# arrow1.set_zorder(-1) # set arrow below plot line
# arrow2 = axes[1].annotate('', xy=(times_average[id], tumor_size_average[id] + shift2), xytext=(times_average[id], tumor_size_average[id] + shift2+1), arrowprops=dict(facecolor='black', width=1.5, headwidth=5))
# arrow2.set_zorder(-1) # set arrow below plot line
legend_elements = [Line2D([0], [0], marker='>', color='black', lw=0, label='Irradiation with 6MeV photon beam')]
#add a tiny text box in the corner with the repo name
plt.figtext(0.01, 0.01, repo, wrap=True, horizontalalignment='left', fontsize=6)
axes[0].set_title('Number of Cells Evolution', fontsize=14)
axes[0].set_xlabel('Time [Day]', fontsize=16)
axes[0].set_ylabel('Number of Cells', fontsize=16)
axes[0].set_xlim(0, tmax)
axes[0].set_ylim(0, 800000)
axes[0].grid(True)
axes[0].legend(fontsize=16, loc='upper left')
axes[1].set_title('Tumor Volume Evolution', fontsize=14)
axes[1].set_xlabel('Time [Day]', fontsize=16)
axes[1].set_ylabel('Tumor Volume [mm^3]', fontsize=16)
axes[1].set_xlim(0, tmax)
axes[1].set_ylim(0, 400)
axes[1].grid(True)
axes[1].legend(fontsize = 16, loc = 'upper left')
plt.tight_layout()
plt.savefig(repo+'/tumor_evolution_average'+str(tmax)+'.png', dpi=dpi)
plt.show()
if show_vessels:
fig, axes = plt.subplots(1, 1, figsize=(8, 5), dpi=dpi)
axes.plot(times_average, number_vessels_average , '-', color = 'crimson', markersize = 5, alpha=0.5, label='Number of Vessels')
axes.fill_between(times_average, np.array(number_vessels_average) - np.array(number_vessels_sd), np.array(number_vessels_average) + np.array(number_vessels_sd), alpha=0.2, color='purple')
axes.set_title('Number of Vessels Evolution')
axes.set_xlabel('Time')
axes.set_ylabel('Number of Vessels')
axes.grid(True)
axes.legend()
plt.tight_layout()
plt.savefig(repo+'/vessels_evolution_average'+str(tmax)+'.png', dpi=dpi)
plt.show()
rates_average = []
dt = times_average[1] - times_average[0]
avg_over = 3
for t in times_average:
idd = np.where(times_average == t)[0][0]
if t <= avg_over*dt:
rates_average.append(0)
else:
rate = (number_cells_average[idd] - number_cells_average[idd-avg_over])/(avg_over*dt)
rates_average.append(rate)
def func_gompertz(x, a, b):
x = np.array(x)
return x * (b - a * np.log(x))
def func_gompertz_(x,t, a, b):
x = np.array(x)
return x * (b - a * np.log(x))
def func_logistic(x, a, b):
x = np.array(x)
return a * x - b * x * x
def func_logistic_(x,t, a, b):
x = np.array(x)
return a * x - b * x * x
def func_holling(x, a, b, k):
x = np.array(x)
return (a * x)/(k + x) - b * x
def func_holling_(x, t, a, b, k):
return (a * x)/(k + x) - b * x
def r2_scores(x, y, popt, func):
residuals = y - func(x, *popt)
ss_res = np.sum(residuals**2)
ss_tot = np.sum((y - np.mean(y))**2)
r_squared = 1 - (ss_res / ss_tot)
return r_squared
def RMSE(x, y, popt, func):
residuals = y - func(x, *popt)
rmse = np.sqrt(np.mean(residuals**2))
return rmse
param0 = np.array([1.0, 1.0, 1.0])
param0_log = np.array([1.0, 100.0])
param0_ = np.array([1.0, 1.0])
#add a random component to the initial guess
# param0 = np.array(param0) * (1 + 1.0 * np.random.random(len(param0)) - 0.1)
weights = np.zeros(len(number_cells_average))
for i in range(len(number_cells_average)):
if number_cells_average[i] < 400000:
weights[i] = 0.2
else:
weights[i] = 1
popt_g, pcov_g = curve_fit(func_gompertz, number_cells_average, rates_average, p0=param0_, maxfev=100000)
popt_l, pcov_l = curve_fit(func_logistic, number_cells_average, rates_average, p0=param0_log, maxfev=100000, sigma=weights)
popt_h, pcov_h = curve_fit(func_holling, number_cells_average, rates_average, p0=param0, maxfev=100000)
print('Fitted parameters Gompertz: ', popt_g)
rmse_g = RMSE(number_cells_average, rates_average, popt_g, func_gompertz)
print('RMSE Gompertz: ', rmse_g)
print('Fitted parameters Logistic: ', popt_l)
rmse_l = RMSE(number_cells_average, rates_average, popt_l, func_logistic)
print('RMSE Logistic: ', rmse_l)
print('Fitted parameters Holling: ', popt_h)
rmse_h = RMSE(number_cells_average, rates_average, popt_h, func_holling)
print('RMSE Holling: ', rmse_h)
#N fin
N_final = popt_h[0]/popt_h[1] - popt_h[2]
print('N final: ', N_final)
#solve the ODE for the Holling model
# find at what time the tumor reaches N_final
times_final = []
for i in range(len(number_cells_average)):
if number_cells_average[i] > N_final:
times_final.append(times_average[i])
break
# fig, axes = plt.subplots(2, 2, figsize=(12, 12), dpi=dpi)
# # popt_r = np.array([1.0, 1.0])
# axes[0, 0].plot(number_cells_average, rates_average, 'o', markersize=3, color='orange', label='Model Values')
# axes[0,0 ].plot(number_cells_average, func_gompertz(number_cells_average, *popt_g), linestyle = 'dotted', color='black', label='Gompertz fit')
# axes[0, 0].plot(number_cells_average, func_logistic(number_cells_average, *popt_l), linestyle = 'dashed', color='black', label='Logistic fit')
# axes[0, 0].plot(number_cells_average, func_holling(number_cells_average, *popt_h), linestyle = 'dashdot', color='black', label='Holling fit')
# axes[0, 0].legend(fontsize = 14)
# axes[1, 0].plot(times_average, rates_average, 'o', markersize=3, color='black')
# axes[0, 1].plot(number_vessels_average, rates_average, 'o', markersize=3, color='crimson')
# axes[1, 1].plot(cycling_cells_average, rates_average, 'o', markersize=3, color='green')
#
# axes[0, 0].set_title('Growth Rate vs Number of Cells and fittings')
# axes[0, 0].set_xlabel('Number of Cells',fontsize=14)
# axes[0, 0].set_ylabel('Growth Rate',fontsize=14)
# axes[0, 0].set_ylim(0, None)
# axes[0, 0].grid(True)
# axes[1, 0].set_title('Growth Rate Evolution')
# axes[1, 0].set_xlabel('Time')
# axes[1, 0].set_ylabel('Growth Rate')
# axes[1, 0].set_ylim(0, None)
# axes[1, 0].grid(True)
# axes[0, 1].set_title('Growth Rate vs Number of Vessels')
# axes[0, 1].set_xlabel('Number of Vessels')
# axes[0, 1].set_ylabel('Growth Rate')
# axes[0, 1].set_ylim(0, None)
# axes[0, 1].grid(True)
# axes[1, 1].set_title('Growth Rate vs Number of Cycling Cells')
# axes[1, 1].set_xlabel('Number of Cycling Cells')
# axes[1, 1].set_ylabel('Growth Rate')
# axes[1, 1].set_ylim(0, None)
# axes[1, 1].grid(True)
# plt.tight_layout()
# plt.savefig(repo + '/growth_rate' + str(tmax) + '.png', dpi=dpi)
# plt.show()
#plot the integral of the growth rate to get the number of cells
# Define parameters
aH = popt_h[0]
bH = popt_h[1]
kH = popt_h[2]
aG = popt_g[0]
bG = popt_g[1]
aL = popt_l[0]
bL = popt_l[1]
# Define time points
t = times_average
# t = np.linspace(0, tmax*3, 6000)
# Set initial condition
x0 = number_cells_average[0]
# Solve the differential equation
x = odeint(func_holling_, x0, t, args=(aH, bH, kH)).flatten()
x2 = odeint(func_gompertz_, x0, t, args=(aG, bG)).flatten()
x3 = odeint(func_logistic_, x0, t, args=(aL, bL)).flatten()
#evaluate pseudo r2
def pseudo_r2_score(y_true, y_pred):
"""Returns the pseudo R^2 score of two arrays"""
y_true = np.array(y_true)
y_pred = np.array(y_pred)
mean_y = np.mean(y_true)
null_deviance = np.sum((y_true - mean_y)**2)
max_likelihood = -0.5 * null_deviance
model_deviance = -0.5 * np.sum((y_true - y_pred)**2)
pseudo_r2 = 1 - (model_deviance / max_likelihood)**(2/len(y_true))
return pseudo_r2
#get the r2 score of the fit
r2_h = pseudo_r2_score(number_cells_average, x)
r2_g = pseudo_r2_score(number_cells_average, x2)
r2_l = pseudo_r2_score(number_cells_average, x3)
print('R2 Holling: ', r2_h)
print('R2 Gompertz: ', r2_g)
print('R2 Logistic: ', r2_l)
fig, axes = plt.subplots(1, 1, figsize=(6, 6), dpi=dpi)
axes.plot(times_average, number_cells_average, '-', label = 'Model values', color='green', alpha=0.8)
axes.plot(t, x, linestyle = 'dashdot', label = 'Holling fit', color='black', alpha=1.0, linewidth=2)
axes.plot(t, x2, linestyle = 'dotted', label = 'Gompertz fit', color='black', alpha=1.0, linewidth=2)
axes.plot(t, x3, linestyle = 'dashed', label = 'Logistic fit', color='black', alpha=1.0, linewidth=2)
axes.fill_between(times_average, np.array(number_cells_average) - np.array(number_cells_sd), np.array(number_cells_average) + np.array(number_cells_sd), alpha=0.2, color='green')
axes.set_xlabel('Time [h]', fontsize=16)
axes.set_ylabel('Number of Cells', fontsize=16)
axes.set_title('Number of cells evolution and fittings', fontsize=16)
axes.legend(fontsize = 14)
axes.grid(True)
plt.tight_layout()
plt.savefig(repo + '/number_cells_fitted' + str(tmax) + '.png', dpi=dpi)
plt.show()