0

I dont understand why the headers of my table are repeated on every row rather than just the first row as expected.

Also why my print("Closest Approach", min(table)) is also repeated onto every row rather than just singularly printing the minimum value of the distances within the table on separate output. Could someone advise on where I have went wrong or how it can be fixed?

Thanks in advance.

I have tried the headers="firstrow" and headers="keys" functions but to no avail.

My link for the code is here,if you can identify problem from output.

Here is the Google Colab code for reference;

def update(i):
    exdata.append(xelist[i])
    eydata.append(yelist[i])
    
    jxdata.append(xjlist[i])
    jydata.append(yjlist[i])
    
    line_e.set_data(exdata,eydata)
    point_e.set_data(xelist[i],yelist[i])
    text_e.set_position((xelist[i],yelist[i]))
    
    line_j.set_data(jxdata,jydata)
    point_j.set_data(xjlist[i],yjlist[i])
    text_j.set_position((xjlist[i],yjlist[i]))
    
    point_s.set_data(xslist[i],yslist[i])
    text_s.set_position((xslist[i],yslist[i]))
    
    ax.set_xlim(-5.8*AU,5.8*AU)
    ax.set_ylim(-5.8*AU,5.8*AU)
    
    dist = sqrt((exdata[-1] - jxdata[-1])**2 + (eydata[-1] - jydata[-1])**2)
    annotation.set_data(x=exdata[-1], y=eydata[-1], dx=jxdata[-1] - exdata[-1], dy=jydata[-1] - eydata[-1])
    text_a.set_position(((exdata[-1] + jxdata[-1]) / 2, (eydata[-1] + jydata[-1]) / 2))
    text_a.set_text(f"{dist/1e9:.1f} km(Mill) ") 
    table = [[(i),(f"{dist/1e9:.1f}")]]

    print("Closest Approach", min(f"{dist/1e9:.1f}"))

    print(tabulate(table, headers=["Time since last Closest Approach (Days)","Distance Between Planets (km*Mill) "]))  
cards
  • 3,936
  • 1
  • 7
  • 25
Orla
  • 23
  • 3
  • use triple ``` for opening and closing a block of code and start at a new line – cards Feb 10 '23 at 18:24
  • Hi @cards, thank you for that tip, I was confused as to how to correctly upload code to the question. Have you any advice relating to my initial problem. I would appreciate any help at all. Thanks again – Orla Feb 10 '23 at 21:14
  • Unfortunately I don't have all the dependencies that the program requires. Notice that at each frame of the animation you are creating a new `tabulate` object. Maybe defined a global list (outside `update`), smt like `tables = [table_i0, table_i1, ...]` which is updated inside `update`, and outside create the `tabulate(tables, headers=...)`? – cards Feb 10 '23 at 21:28

0 Answers0