![](https://img-blog.csdnimg.cn/img_convert/64bb16d5dc97f4c11478e33d586b5456.png)
![](https://img-blog.csdnimg.cn/img_convert/bf63f49b0b7fb0d89e1b4d7aad7b61dd.png)
![](https://img-blog.csdnimg.cn/img_convert/3963a7e51d9847286a975429383905fa.png)
![](https://img-blog.csdnimg.cn/img_convert/a0bcae8309e23c4e810ed9743efb208c.png)
![](https://img-blog.csdnimg.cn/img_convert/a858367d3dd338fbeb48a7253993c787.png)
![](https://img-blog.csdnimg.cn/img_convert/5c1702c83b2124b3f79b9a238b99e112.png)
上述图片参考自-《公路桥梁抗震设计规范》(JTGT 2231-01—2020)
import numpy as np #导入numpy库
import matplotlib.pyplot as plt #导入绘图库
plt.style.use("bmh") #设置不同风格样式,还可以选择classic
plt.rcParams['font.sans-serif'] = ['SimSun']#设置字体
plt.rcParams['axes.unicode_minus'] = False#确保 Matplotlib 绘图中的负号显示正确。
b5 = 0.04 #反应谱最大值
d5 = 0.35 #周期
f5 = 0.02 #起点
g5 = 6 #最大时间
h5 = 0.02 #时间步长
#反应谱公式
def S(T5):
Smax = b5
if T5 <= 0.1:
return Smax*((0.6*T5)/0.1)
elif 0.1 < T5 < d5:
return Smax
elif d5 < T5 <= g5:
return Smax*(d5/T5)
T5_range = np.linspace(f5, g5, int(g5/h5))
S_range = [S(T5) for T5 in T5_range]
#绘图
plt.figure("设计加速度反应谱",(12,8))
plt.plot(T5_range, S_range)
plt.xlabel("时间 (s)")
plt.ylabel("设计加速度反应谱")
plt.xlim(0,6)
plt.ylim(bottom=0)
plt.show()
#导出文件
with open("data.txt", "w") as file:
for i in range(len(T5_range)):
file.write(str(T5_range[i]) + " " + str(S_range[i]) + "\n")
![](https://img-blog.csdnimg.cn/img_convert/341653abda9771e2296a608781088967.png)
![](https://img-blog.csdnimg.cn/img_convert/a4380389259eb230042e3683aec41887.png)
![](https://img-blog.csdnimg.cn/img_convert/a9365acf6a4162cdd4941ee1c7de78f4.png)