Python画弯矩图,都以分段直线近似代替曲线,分段越多,越接近真实的弯矩曲线,就像这样
import matplotlib.pyplot as plt
import numpy as np
fig, axs = plt.subplots(1, 1, constrained_layout=True)
axs.plot([0,1,5],[0,2,1], linewidth=2, color="dimgrey")
plt.show()
除了大致轮廓,还可以把细节完善一下。比如两端封闭起来,填充颜色等等。以受均布荷载的简支梁为例
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif'] = ['SimHei'] # 正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 正常显示负号
l = 5
q = 20
x = np.linspace(0,l,20) #将梁20等分
M = q/2*(l*x-x**2) #计算等分点弯矩M
V = q*(l/2-x) #计算等分点剪力V
fig, axs = plt.subplots(2, 1, constrained_layout=True,figsize=(8,4) )
axs[0].invert_yaxis()
axs[0].plot(x,M, label="M1", linewidth=3) #画弯矩图
axs[0].fill_between(x, 0, M, alpha=0.3, where=(M<=0) )
axs[0].fill_between(x, 0, M, alpha=0.3, where=(M>=0) )
axs[0].plot([0,5],[0,0], linewidth = 2, color = "dimgrey") #画梁
axs[0].set_ylabel('弯矩(kN.m)', fontsize = 16)
fig.suptitle('内力图', fontsize = 18)
x1 = np.array( [0] )
x2 = np.array( [l] )
x3 = np.hstack( (x1, x, x2) )
v1 = np.array( [ 0 ] )
v3 = np.hstack( (v1, V, v1) )
axs[1].plot(x3, v3, label="M1", linewidth=3)#画剪力图
axs[1].set_ylabel('剪力(kN)', fontsize = 16)
axs[1].fill_between(x, 0, V, alpha=0.3, where=(V<=0) ) #填充颜色
axs[1].fill_between(x, 0, V, alpha=0.3, where=(V>=0) )
axs[1].plot([0,5],[0,0], linewidth = 2, color = "dimgrey") #画梁
fig.savefig('./f2.png', dpi = 500) #保存图片
plt.show()
再看一个多跨梁
弯矩图注意事项:
剪力图注意事项:
弯矩图是一条表示杆件不同截面弯矩的曲线。这里所说的曲线是广义的,它包括直线、折线和一般意义的曲线。弯矩图是对构件弯矩的图形表示,弯矩图画在受拉侧,无须标正负号。