I am plotting multiple line and scatter graphs on a single figure and axis. My code sets one variable called total_steel_area and then goes through a set of values of another variable called phi_x__h. It then calculates x and y values from these variables and places them in a list. It then plots the values. The code then moves to the next value of total_steel_area and repeats. The output graph is shown below.
The diagonal lines connect the last value of one set of x,y values to the first value of the next set. My question is how can I remove this connecting line?
My code is below:
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()
You should initialize/reset your lists at each step of the outer loop:
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)
There might be a vectorial way to compute your values, but this is difficult to guess without a reproducible example of the functions.
Output: