0

I am trying to model an orbit using a 4th order Runge-Kutta method, which works and gives a good numerical output. My issue is that when I try and plot the orbit around a fixed point, I can only see it if I specify that each data point is a point. This code is below:

T, X, Y, V_X, V_Y = orbit(x, y, v_x, v_y)
results = [(X, Y)]
results = np.array(results) #converts the results list to an array that can be called upon for the values of x and y for the graph
X = results[:,0] #gets values for x for graph
Y = results[:,1] #gets values for y for graph
pp.axis('equal')
pp.plot(X, Y, 'o') #plots graph of above X and Y with circular points connected by a line.
pp.scatter(0,0, s=1000, color='g')
pp.show()

This gives an output of:

enter image description here

when I get rid of the 'o' in the pp.plot line, the line vanishes. My only thought is that the thickness is very narrow compared to the scales on the graph, but I have never had this issue before.

DavidG
25.6k14 gold badges101 silver badges87 bronze badges
asked Mar 8, 2019 at 10:49
2
  • 2
    Could you please provide some data to test your code on? Also, the fact that the line is multi-coloured suggests that multiple lines are being plotted. What are the shapes of X and Y? Commented Mar 8, 2019 at 11:05
  • 2
    I think it might be because results is not a simple array. Might be an array of tuples... Can you show what results looks like? Commented Mar 8, 2019 at 11:07

1 Answer 1

1

Test only this:

T, X, Y, V_X, V_Y = orbit(x, y, v_x, v_y)
pp.axis('equal')
pp.plot(X, Y) #plots graph of above X and Y with circular points connected by a line.
pp.scatter(0,0, s=1000, color='g')
pp.show()
answered Mar 8, 2019 at 11:10
Sign up to request clarification or add additional context in comments.

1 Comment

This has made the output one thick blue line, cutting down the time interval I was doing it over has also helped as the orbit does decay slowly. Thank you very much for your help with this!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.