1

I have a text file with lots of data that is arranged in 2 columns. I need to use the data in the 2nd column in a formula (which outputs Energy). I need to plot that energy against the time which is all the data in the first column. So far I have this, and it prints a very weird graph. I know that the energy should be oscillating and decaying exponentially.

import numpy as np
import matplotlib.pyplot as plt

m = 0.090
l = 0.089
g = 9.81

H = np.loadtxt("AngPosition_3p5cmSeparation.txt")
x, y = np.hsplit(H,2)
Ep = m*g*l*(1-np.cos(y))
plt.plot(x, Ep)
plt.show()

I'm struggling to see where I have gone wrong, but then again I am somewhat new to Python. Any help is much appreciated.

1
  • PS: I have tried splitting the data in two separate files and the same graph is still shown. Commented Oct 31, 2013 at 10:38

1 Answer 1

1

I managed to get it to work. My problem was that the angle data had to be converted into radians. I couldn't do that automatically in Python using math.radians for some reason so I just edited the data in Excel and then back into Notepad.

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

Comments

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.