ARTICLE AD BOX
I have a while loop that is running 5000 times a second. Each time it runs it recalculates a whole ton of variables and then adds the value of a couple of those varibles to their own lists. After a set amount of time the while loop breaks and those lists are graphed using matplotlib.
(pictured below)
while (True): rate(5000) star.force = gforce(star,star2) + gforce(star,star3)+ gforce(star,uto) star2.force = gforce(star2,star) + gforce(star2,star3) + gforce(star2,uto) star3.force = gforce(star3,star) + gforce(star3,star2) + gforce(star3,uto) uto.force = gforce(uto,star) + gforce(uto,star2) + gforce(uto,star3) star.momentum = star.momentum + star.force*dt star2.momentum = star2.momentum + star2.force*dt star3.momentum = star3.momentum + star3.force*dt uto.momentum = uto.momentum + uto.force*dt star.pos = star.pos + star.momentum/star.mass*dt star2.pos = star2.pos + star2.momentum/star2.mass*dt star3.pos = star3.pos + star3.momentum/star3.mass*dt uto.pos = uto.pos + uto.momentum/uto.mass*dt t = t + dt a = a + 1 b = a/5000 star3force_list.append(star3.force.mag) star2force_list.append(star2.force.mag) if b == 5: break print("Done!"); plt.plot(star3force_list) plt.plot(star2force_list) plt.ylabel('Force') plt.show()The issue with this is that the Matplotlib auto labels the scale of the x axis with how many data points were graphed, so the resulting graphs have a range from 0, to 50000 if I only run it for 10 seconds. I would much rather have the x axis be labeled in the seconds instead but every solution I have tried to rename things has resulted in only the first 10 data points being tabled 1-10 and the other 49990 being left blank.
I'm a beginner when it comes to coding so I'm not well versed in a lot of the different things you can do with python so I'm sure that there is a very simple way to fix this, but none of my searches have turned up what I'm looking for (I refuse to ask a bot). Does anyone have any suggestions?
(Edit: just felt I should add that the bulk of this code was not originally mine (it's not all shown here). I followed a short guide on using a library called vpython to make a physics simulation of a galaxy. After I got the base structure of it I started branching out which is how I ended up on this question.
the libraries I'm currently using are vpython, Matplotlib, and numpy)
