我正在单个图形和轴上绘制多条线图和散点图。我的代码设置一个名为total_steel_area 的变量,然后遍历另一个名为phi_x__h 的变量的一组值。然后,它根据这些变量计算 x 和 y 值并将它们放入列表中。然后绘制值。然后代码移至total_steel_area 的下一个值并重复。输出图如下所示。
对角线将一组 x,y 值的最后一个值连接到下一组的第一个值。我的问题是如何删除这条连接线?
我的代码如下:
phi_N_bh = []
phi_M_bh2 = []
fig, ax = plt.subplots(dpi=100, figsize=(8,4))
for total_steel_area in np.arange(0.01,0.06,0.01):
for phi_x__h in np.arange(0.1,2,0.1):
phi_N__bh, phi_M__bh2 = calculate_phi_N__bh_and_phi_M__bh2(phi_x__h, lamb, alpha_cc, eta, f_ck, E_s, varepsilon_cu2, phi_d__h, phi_d2__h, f_yk, total_steel_area/2, total_steel_area/2)
phi_N_bh.append(phi_N__bh)
phi_M_bh2.append(phi_M__bh2)
ax.plot(phi_M_bh2, phi_N_bh, c='b')
ax.scatter(phi_M_bh2, phi_N_bh, c='b', s=10)
ax.set_title('Column Design Chart for Rectangular Column with Symmetrical Compression and Tension Reinforcement')
ax.set_xlabel('M/bh²')
ax.set_ylabel('N/bh')
ax.text(1-0.1, 1-0.1, f'f_ck = {f_ck}, f_yk = {f_yk}', horizontalalignment='center',
verticalalignment='center', transform=ax.transAxes)
ax.text(1-0.1, 1-0.2, f'd/h = {phi_d__h}, d2/h = {phi_d2__h}', horizontalalignment='center',
verticalalignment='center', transform=ax.transAxes)
ax.set_ylim(0)
ax.set_xlim(0)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.legend()
您应该在外循环的每一步重置列表:
for total_steel_area in np.arange(0.01,0.06,0.01):
phi_N_bh = []
phi_M_bh2 = []
for phi_x__h in np.arange(0.1,2,0.1):
phi_N__bh, phi_M__bh2 = calculate_phi_N__bh_and_phi_M__bh2(phi_x__h, lamb, alpha_cc, eta, f_ck, E_s, varepsilon_cu2, phi_d__h, phi_d2__h, f_yk, total_steel_area/2, total_steel_area/2)
phi_N_bh.append(phi_N__bh)
phi_M_bh2.append(phi_M__bh2)
ax.plot(phi_M_bh2, phi_N_bh, c='b')
ax.scatter(phi_M_bh2, phi_N_bh, c='b', s=10)