|
5 | 5 |
|
6 | 6 | import matplotlib.pyplot as plt |
7 | 7 | from matplotlib import gridspec |
8 | | -from ipywidgets import interactive |
| 8 | +from ipywidgets import interactive |
9 | 9 | import ipywidgets as widgets |
10 | 10 | import numpy as np |
11 | 11 |
|
| 12 | + |
12 | 13 | def pwpplot(timeStep): |
13 | | - Step = int(timeStep / 0.01)-1 |
| 14 | + Step = int(timeStep / 0.01) - 1 |
14 | 15 | plt.subplot(211) |
15 | 16 | plt.plot(time, uu) |
16 | | - plt.plot(time[Step],uu[Step],'ro') |
17 | | - plt.ylabel('pwp(kPa)') |
| 17 | + plt.plot(time[Step], uu[Step], "ro") |
| 18 | + plt.ylabel("pwp(kPa)") |
18 | 19 | plt.grid() |
19 | 20 | plt.subplot(212) |
20 | | - plt.plot(time,acc_input) |
21 | | - plt.plot(time[Step],acc_input[Step],'ro') |
22 | | - plt.xlabel('time(s)') |
23 | | - plt.ylabel('acceleration(g)') |
| 21 | + plt.plot(time, acc_input) |
| 22 | + plt.plot(time[Step], acc_input[Step], "ro") |
| 23 | + plt.xlabel("time(s)") |
| 24 | + plt.ylabel("acceleration(g)") |
24 | 25 | plt.grid() |
25 | 26 |
|
| 27 | + |
26 | 28 | def dispplot(timeStep): |
27 | | - Step = int(timeStep / 0.01)-1 |
| 29 | + Step = int(timeStep / 0.01) - 1 |
28 | 30 | plt.figure(figsize=(7, 8)) |
29 | 31 | ax0 = plt.subplot(gs[0]) |
30 | | - ax0.plot(maxdisp[0, ::2], nodes[::2, 2], 'b--') |
31 | | - ax0.plot(mindisp[0, ::2], nodes[::2, 2], 'b--') |
| 32 | + ax0.plot(maxdisp[0, ::2], nodes[::2, 2], "b--") |
| 33 | + ax0.plot(mindisp[0, ::2], nodes[::2, 2], "b--") |
32 | 34 | ax0.plot(disp[Step, ::4], nodes[::2, 2]) |
33 | | - plt.xlabel('displacement(m)') |
34 | | - plt.ylabel('Elevation(m)') |
| 35 | + plt.xlabel("displacement(m)") |
| 36 | + plt.ylabel("Elevation(m)") |
35 | 37 | plt.grid() |
36 | 38 | ax1 = plt.subplot(gs[1]) |
37 | | - ax1.plot(time,acc_input) |
38 | | - ax1.plot(time[Step],acc_input[Step],'ro') |
39 | | - plt.xlabel('time(s)') |
40 | | - plt.ylabel('acceleration(g)') |
| 39 | + ax1.plot(time, acc_input) |
| 40 | + ax1.plot(time[Step], acc_input[Step], "ro") |
| 41 | + plt.xlabel("time(s)") |
| 42 | + plt.ylabel("acceleration(g)") |
41 | 43 | plt.grid() |
42 | 44 |
|
| 45 | + |
43 | 46 | def createpwpplot(): |
44 | 47 | global time, acc_input, uu |
45 | | - pwp = np.loadtxt('porePressure.out') |
46 | | - time = pwp[:,0] |
| 48 | + pwp = np.loadtxt("porePressure.out") |
| 49 | + time = pwp[:, 0] |
47 | 50 | pwp = np.delete(pwp, 0, 1) |
48 | 51 | uexcess = pwp - pwp[0, :] |
49 | | - uu = uexcess[0:len(time), 12] |
50 | | - acc = np.loadtxt('acceleration.out') |
| 52 | + uu = uexcess[0 : len(time), 12] |
| 53 | + acc = np.loadtxt("acceleration.out") |
51 | 54 | acc_input = acc[:, 1] |
52 | 55 |
|
53 | | - return interactive(pwpplot,timeStep = widgets.FloatSlider(min = 0.01, max = time[-1], step = 0.01)) |
| 56 | + return interactive( |
| 57 | + pwpplot, timeStep=widgets.FloatSlider(min=0.01, max=time[-1], step=0.01) |
| 58 | + ) |
54 | 59 |
|
55 | 60 |
|
56 | 61 | def createDispplot(): |
57 | 62 | global maxdisp, mindisp, nodes, disp, gs |
58 | | - nodes = np.loadtxt('nodesInfo.dat') |
59 | | - disp = np.loadtxt('displacement.out') |
| 63 | + nodes = np.loadtxt("nodesInfo.dat") |
| 64 | + disp = np.loadtxt("displacement.out") |
60 | 65 | disp = np.delete(disp, 0, 1) |
61 | | - disp = (disp.transpose() - disp[:,0]).transpose() |
| 66 | + disp = (disp.transpose() - disp[:, 0]).transpose() |
62 | 67 | ndof = 2 |
63 | 68 | nnodes = nodes.shape[0] |
64 | 69 | maxdisp = np.amax(disp, axis=0) |
65 | 70 | mindisp = np.amin(disp, axis=0) |
66 | 71 | maxdisp = maxdisp.reshape(ndof, nnodes, order="F") |
67 | 72 | mindisp = mindisp.reshape(ndof, nnodes, order="F") |
68 | | - gs = gridspec.GridSpec(2, 1, height_ratios=[6, 1]) |
| 73 | + gs = gridspec.GridSpec(2, 1, height_ratios=[6, 1]) |
| 74 | + |
| 75 | + return interactive( |
| 76 | + dispplot, |
| 77 | + timeStep=widgets.FloatSlider(min=0.01, max=time[-1], step=0.01), |
| 78 | + continuous_update=False, |
| 79 | + ) |
69 | 80 |
|
70 | | - return interactive(dispplot,timeStep = widgets.FloatSlider(min = 0.01, max = time[-1], step = 0.01), continuous_update=False) |
71 | 81 |
|
72 | 82 | if __name__ == "__main__": |
73 | | - createpwpplot() |
| 83 | + createpwpplot() |
0 commit comments