2

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()

Graph showing multiple plots and unwanted connecting line

5
  • What is calculate_phi_N__bh_and_phi_M__bh2? Please provide the function, and all needed variables to form a minimal reproducible example. Commented Jan 16 at 18:24
  • @mozway it is a complicated function. At the end though it just calculates two numbers which it will append to phi_N_bh and phi_M_bh2 Commented Jan 16 at 18:29
  • Then provide a dummy example that allows us to reproduce your issue. Commented Jan 16 at 18:30
  • my other functions are too long to add as a comment, how can I share all my functions with you? Commented Jan 16 at 18:34
  • I provided what I think is the answer, I'll let you test it. If this works I'd appreciate if you can add the output image in the answer Commented Jan 16 at 18:36

1 Answer 1

0

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:

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, thank you that solved it. Looks like I was appending every value to the list which is why they were joined together. I am unsure how to add the output plot to this reply?
@Kevin you can suggest an edit to the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.