-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_def.py
129 lines (117 loc) · 5.68 KB
/
plot_def.py
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
def plot_cplxTimesRot(a, b, phi):
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax0 = plt.axes()
ax0.set_aspect('equal', 'box')
ax0.grid(True)
plt.title("Komplex")
plt.xlim(-2.5,2.5)
plt.xticks([-2,-1,0,1,2])
plt.text(2,0.1,"Re")
plt.ylim(-2.5, 2.5)
plt.yticks([-2,-1,0,1,2])
plt.text(-0.1,2,"Im")
ax0.spines['left'].set_position('zero')
ax0.spines['right'].set_color('none')
ax0.spines['bottom'].set_position('zero')
ax0.spines['top'].set_color('none')
ax0.arrow(-2.5, 0, 5, 0, color='k', head_width=0.1, length_includes_head=True)
ax0.arrow(0, -2.5, 0, 5, color='k', head_width=0.1, length_includes_head=True)
z0 = a + 1j*b
z0rot = z0 * np.exp(1j*np.deg2rad(phi))
ax0.arrow(0, 0, np.real(z0), np.imag(z0), color=[0.7,0.7,0.7], head_width=0.1, length_includes_head=True)
ax0.arrow(0, 0, np.real(z0rot), np.imag(z0rot), color='b', head_width=0.1, length_includes_head=True)
alpha = np.linspace(0,2*np.pi,101)
ax0.plot(np.abs(z0)*np.cos(alpha), np.abs(z0)*np.sin(alpha), color=[0.7,0.7,0.7], linestyle=':')
plt.show()
def plot_u0iL(funu, funi, t):
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure(constrained_layout=False, figsize=(20,4))
gs = fig.add_gridspec(1,3)
ax0 = fig.add_subplot(gs[0,0])
ax0.set_aspect('equal', 'box')
ax0.grid(True)
plt.title("Komplex (gedreht!)")
plt.xlim(2.5,-2.5)
plt.xticks([-2,-1,0,1,2])
plt.text(2,0.1,"Im")
plt.ylim(-2.5, 2.5)
plt.yticks([-2,-1,0,1,2])
plt.text(-0.1,2,"Re")
ax0.spines['left'].set_position('zero')
ax0.spines['right'].set_color('none')
ax0.spines['bottom'].set_position('zero')
ax0.spines['top'].set_color('none')
ax0.arrow(-2.5, 0, 5, 0, color='k', head_width=0.1, length_includes_head=True)
ax0.arrow(0, -2.5, 0, 5, color='k', head_width=0.1, length_includes_head=True)
ax0.arrow(0, 0, np.imag(funu(t)), np.real(funu(t)), color='b', head_width=0.1, length_includes_head=True)
ax0.plot([np.imag(funu(t)), -2.5], [np.real(funu(t)),np.real(funu(t))], color='b', linestyle=':')
ax0.arrow(0, 0, np.imag(funi(t)), np.real(funi(t)), color='r', head_width=0.1, length_includes_head=True)
ax0.plot([np.imag(funi(t)), -2.5], [np.real(funi(t)),np.real(funi(t))], color='r', linestyle=':')
# ax0.plot([0,np.real(fun(t))], [-2, -2], color='b')
ax1 = fig.add_subplot(gs[0,1:])
ax1.grid(True)
plt.title("Zeitbereich (Realteil des komplexen Momentanwerts)")
plt.xlim(0, 10)
plt.xticks([0,1,2,3,4,5,6,7,8,9,10])
plt.xlabel("t (s)")
plt.ylim(-2.5, 2.5)
plt.yticks([-2,-1,0,1,2])
tt = np.arange(0, t+1e-6, 0.1)
ax1.plot(tt, np.real(funu(tt)), color='b', label="u0(t)")
ax1.plot([0, t], [np.real(funu(t)),np.real(funu(t))], color='b', linestyle=':')
ax1.plot(tt, np.real(funi(tt)), color='r', label="iL(t)")
ax1.plot([0, t], [np.real(funi(t)),np.real(funi(t))], color='r', linestyle=':')
plt.legend()
plt.show()
def plot_u0iRCuCuR(funu0, funiRC, funuR, funuC, t):
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure(constrained_layout=False, figsize=(20,4))
gs = fig.add_gridspec(1,3)
ax0 = fig.add_subplot(gs[0,0])
ax0.set_aspect('equal', 'box')
ax0.grid(True)
plt.title("Komplex (gedreht!)")
plt.xlim(2.5,-2.5)
plt.xticks([-2,-1,0,1,2])
plt.text(2,0.1,"Im")
plt.ylim(-2.5, 2.5)
plt.yticks([-2,-1,0,1,2])
plt.text(-0.1,2,"Re")
ax0.spines['left'].set_position('zero')
ax0.spines['right'].set_color('none')
ax0.spines['bottom'].set_position('zero')
ax0.spines['top'].set_color('none')
ax0.arrow(-2.5, 0, 5, 0, color='k', head_width=0.1, length_includes_head=True)
ax0.arrow(0, -2.5, 0, 5, color='k', head_width=0.1, length_includes_head=True)
ax0.arrow(0, 0, np.imag(funu0(t)), np.real(funu0(t)), color='b', head_width=0.1, length_includes_head=True)
ax0.plot([np.imag(funu0(t)), -2.5], [np.real(funu0(t)),np.real(funu0(t))], color='b', linestyle=':')
ax0.arrow(0, 0, np.imag(funiRC(t)), np.real(funiRC(t)), color='r', head_width=0.1, length_includes_head=True)
ax0.plot([np.imag(funiRC(t)), -2.5], [np.real(funiRC(t)),np.real(funiRC(t))], color='r', linestyle=':')
ax0.arrow(0, 0, np.imag(funuR(t)), np.real(funuR(t)), color=[0,0.6,0], head_width=0.1, length_includes_head=True)
ax0.plot([np.imag(funuR(t)), -2.5], [np.real(funuR(t)),np.real(funuR(t))], color=[0,0.6,0], linestyle=':')
ax0.arrow(0, 0, np.imag(funuC(t)), np.real(funuC(t)), color=[0.7,0.7,0], head_width=0.1, length_includes_head=True)
ax0.plot([np.imag(funuC(t)), -2.5], [np.real(funuC(t)),np.real(funuC(t))], color=[0.7,0.7,0], linestyle=':')
# ax0.plot([0,np.real(fun(t))], [-2, -2], color='b')
ax1 = fig.add_subplot(gs[0,1:])
ax1.grid(True)
plt.title("Zeitbereich (Realteil des komplexen Momentanwerts)")
plt.xlim(0, 10)
plt.xticks([0,1,2,3,4,5,6,7,8,9,10])
plt.xlabel("t (s)")
plt.ylim(-2.5, 2.5)
plt.yticks([-2,-1,0,1,2])
tt = np.arange(0, t+1e-6, 0.1)
ax1.plot(tt, np.real(funu0(tt)), color='b', label="u0(t)")
ax1.plot([0, t], [np.real(funu0(t)),np.real(funu0(t))], color='b', linestyle=':')
ax1.plot(tt, np.real(funiRC(tt)), color='r', label="iRC(t)")
ax1.plot([0, t], [np.real(funiRC(t)),np.real(funiRC(t))], color='r', linestyle=':')
ax1.plot(tt, np.real(funuR(tt)), color=[0,0.6,0], label="uR(t)")
ax1.plot([0, t], [np.real(funuR(t)),np.real(funuR(t))], color=[0,0.6,0], linestyle=':')
ax1.plot(tt, np.real(funuC(tt)), color=[0.7,0.7,0], label="uC(t)")
ax1.plot([0, t], [np.real(funuC(t)),np.real(funuC(t))], color=[0.7,0.7,0], linestyle=':')
plt.legend()
plt.show()