-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyplot.py
More file actions
97 lines (81 loc) · 2.82 KB
/
pyplot.py
File metadata and controls
97 lines (81 loc) · 2.82 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
File = open("test.txt", 'r')
text = File.readline()
print(text, end='')
File.seek(0)
for line in File:
print(line, end='')
print('')
File.close();
import json
diction = {'a': 1, 'b': 2, 'c': 3}
s1 = json.dumps(diction)
print(s1)
s2 = json.dumps(diction, sort_keys=True, indent=4)
print(s2)
string = '123456'
print(string[-4: -1])
# import numpy as np
# import matplotlib
# import matplotlib.pyplot as plt
#
# matplotlib.rcParams['font.family'] = 'SimHei'
# matplotlib.rcParams['font.sans-serif'] = ['SimHei']
# x = np.linspace(0, 6, 100)
# y = np.cos(2 * np.pi * x) * np.exp(-x)+0.8
# plt.plot(x, y, 'k', color='r', linewidth=3, linestyle="-")
# plt.show()
#
# plt.plot([1, 2, 4], [1, 2, 3])
# plt.title("坐标系标题")
# plt.xlabel('时间 (s)')
# plt.ylabel('范围 (m)')
# plt.xticks([1, 2, 3, 4, 5], [r'$\pi/3$', r'$2\pi/3$', r'$\pi$',
# r'$4\pi/3$', r'$5\pi/3$'])
# plt.show()
# x = np.linspace(0, 6, 200)
# y = np.cos(2 * np.pi * x) * np.exp(-x) + 0.8
# plt.plot(x, y, 'k', color='r', label="$exp-decay$", linewidth=3)
# plt.axis([0, 6, 0, 1.8])
# ix = (x > 0.8) & (x < 3)
# plt.fill_between(x, 0, y, where=ix,
# facecolor='grey', alpha=0.25)
# plt.text(0.5 * (0.8 + 3), 0.2, r"$\int_a^b f(x)\mathrm{d}x$",
# horizontalalignment='center')
# plt.legend()
# plt.show()
##e18.1PlotDamping.py
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family'] = 'SimHei'
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
def Draw(pcolor, nt_point, nt_text, nt_size):
plt.plot(x, y, 'k', label="$exp_decay$", color=pcolor, linewidth=3, linestyle="-")
plt.plot(x, z, "b--", label="$cos(x^2)$", linewidth=1)
plt.xlabel('时间(s)')
plt.ylabel('幅度(mV)')
plt.title("阻尼衰减曲线绘制")
plt.annotate('$\cos(2 \pi t) \exp(-t)$', xy=nt_point, xytext=nt_text, fontsize=nt_size,
arrowprops=dict(arrowstyle='->', connectionstyle="arc3,rad=.1"))
def Shadow(a, b):
ix = (x > a) & (x < b)
plt.fill_between(x, y, 0, where=ix, facecolor='grey', alpha=0.25)
plt.text(0.5 * (a + b), 0.2, "$\int_a^b f(x)\mathrm{d}x$",
horizontalalignment='center')
def XY_Axis(x_start, x_end, y_start, y_end):
plt.xlim(x_start, x_end)
plt.ylim(y_start, y_end)
plt.xticks([np.pi / 3, 2 * np.pi / 3, 1 * np.pi, 4 * np.pi / 3, 5 * np.pi / 3],
['$\pi/3$', '$2\pi/3$', '$\pi$', '$4\pi/3$', '$5\pi/3$'])
x = np.linspace(0.0, 6.0, 100)
y = np.cos(2 * np.pi * x) * np.exp(-x) + 0.8
z = 0.5 * np.cos(x ** 2) + 0.8
note_point, note_text, note_size = (1, np.cos(2 * np.pi) * np.exp(-1) + 0.8), (1, 1.4), 14
fig = plt.figure(figsize=(8, 6), facecolor="white")
# plt.subplot(111)
Draw("red", note_point, note_text, note_size)
XY_Axis(0, 5, 0, 1.8)
Shadow(0.8, 3)
plt.legend()
plt.savefig('sample.JPG')
plt.show()